第一步:编写验证码的Action
第三步:编写jsp页面(采用jquery实现动态刷新)
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>验证码</title> <script type="text/javascript" src="js/jquery-1.6.2.min.js"> </script> <script type="text/javascript"> function changeImg(){ $("#authCode").attr("src","test/authCode.action?d="+new Date().valueOf()); } </script> </head> <body> <center> <br> <img src="test/authCode.action" alt="验证码" id="authCode" onclick="changeImg()"> <a href="#" onclick="changeImg()">看不清,换一张!</a> </center> </body> </html>