public class CodeServlert extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//使用jar生产验证码
ValidateCode vCode = new ValidateCode(100, 25, 4, 9);
//获取生产的验证码字符串
String code =vCode.getCode();
//传值方式1.拼接网址字符串 2.使用域对象
//使用session 来储存验证码
request.getSession().setAttribute("wcode", code);
System.out.println(code);
//写到网页上 (通过 响应中的字符流 写回网页)
vCode.write(response.getOutputStream());
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
jsp代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.