如何写验证码 关于用户登录时,要填写验证码!可是这个验证码的代码是如何写的呢?请各位高手指点指点!先谢了!~ 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考我们编写的jsp教程:http://family168.com/tutorial/jsp/html/jsp-ch-12.html#jsp-ch-12-01 写一个生产验证码的aciton或者servlet随机数—画随机数到图片--存储字符串到session通过比对客户输入的字符串和存在session中的字符串换一张采用ajax即可 <tr> <td valign="top" class="w1"> 验证码: </td> <td> <img class="yzm_img" id='imgVcode' src="createImage.do"/> <input name="txtVerifyCode" type="text" id="txtVerifyCode" class="yzm_input" onblur="" /> <div class="text_left t1"> <p class="t1"> <span id="vcodeValidMsg">请输入图片中的四个字母。</span><a href="#" onclick="javascript:$('imgVcode').src='createImage.do?'+new Date().getTime()">看不清楚?换个图片</a> </p> </div> </td> </tr> public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // 设置响应类型 //response.setContentType("text/html"); response.setContentType("image/jpeg"); // 图片的内存映像 点阵信息 BufferedImage image = new BufferedImage(80, 20, BufferedImage.TYPE_INT_RGB); Random r = new Random();// //获得画笔对象 Graphics g = image.getGraphics(); //setColor设置当前画笔的颜色 g.setColor(new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255))); g.fillRect(0, 0, 80, 20); g.setColor(new Color(255,255,255)); g.setColor(new Color(0, 0, 0)); String number = String.valueOf(r.nextInt(99999)); HttpSession session = request.getSession(); session.setAttribute("txtVerifyCode", number); g.drawString(number, 15, 15); // 压缩成jpeg格式 OutputStream os = response.getOutputStream(); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os); // 把BufferedImage对象中的图像信息编码后 // 向创建该对象(encoder)时指定的输出流输出 encoder.encode(image); return null; } Spring整合Hibernate后,如何使用SchemaExport生成数据库表 struts2流程简单问题(我是初学者) filter的执行顺序问题 Java后台生成的Word文档只能保存在后台,怎么保存在客户端。 在线急等 mysql 一条转换语句 求用Java解决三种不同情况下的算法. 大家帮忙看看这条错误怎么调? 如何将一个jdom对象一XML格式输出到jsp页面上?在线等。。急··· 关于APACHE的MINA框架的问题!!!!!!!! JB8+WebLogic7的问题 Hibernate中怎么不能从1的一端更新N的一端呢?? Tomcat与jboss相比,哪个做服务器更好
参考我们编写的jsp教程:http://family168.com/tutorial/jsp/html/jsp-ch-12.html#jsp-ch-12-01
随机数—画随机数到图片--存储字符串到session通过比对客户输入的字符串和存在session中的字符串换一张采用ajax即可
<td valign="top" class="w1">
验证码:
</td>
<td>
<img class="yzm_img" id='imgVcode' src="createImage.do"/>
<input name="txtVerifyCode" type="text" id="txtVerifyCode"
class="yzm_input" onblur="" />
<div class="text_left t1">
<p class="t1">
<span id="vcodeValidMsg">请输入图片中的四个字母。</span><a href="#" onclick="javascript:$('imgVcode').src='createImage.do?'+new Date().getTime()">看不清楚?换个图片</a>
</p>
</div>
</td>
</tr>
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// 设置响应类型
//response.setContentType("text/html");
response.setContentType("image/jpeg");
// 图片的内存映像 点阵信息
BufferedImage image = new BufferedImage(80, 20,
BufferedImage.TYPE_INT_RGB);
Random r = new Random();
// //获得画笔对象
Graphics g = image.getGraphics();
//setColor设置当前画笔的颜色
g.setColor(new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
g.fillRect(0, 0, 80, 20);
g.setColor(new Color(255,255,255));
g.setColor(new Color(0, 0, 0));
String number = String.valueOf(r.nextInt(99999));
HttpSession session = request.getSession();
session.setAttribute("txtVerifyCode", number);
g.drawString(number, 15, 15); // 压缩成jpeg格式
OutputStream os = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(os); // 把BufferedImage对象中的图像信息编码后
// 向创建该对象(encoder)时指定的输出流输出
encoder.encode(image);
return null;
}