1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% 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>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript"> function changeImg(img){ img.src = img.src + "?" + new Date().getTime(); } </script> </head> <body> <form action="/web/servlet/check" method="post"> 用户名:<input type="text" name="username"> 密码 :<input type="password" name="password"><br/><br/> 验证码:<input type = "text" name="checkcode"> <img src="http://localhost:8080/random/servlet/Test1" onclick="changeImg(this)"/> <input type="submit" value="注册"> </form> </body> </html>
check:
request.setCharacterEncoding("UTF-8");
String c_checkcode = request.getParameter("checkcode");
String s_checkcode = request.getSession().getAttribut("checkcode");
if(c_checkcode!=null && s_checkcode!=null && c_checkcode.equals(s_checkcode)){
System.out.println("处理注册请求“);
}else{
System.out.println("验证码错误");
}