kaptcha是一個簡單好用的驗證碼生成工具
<?xml version=
xmlns=
xmlns:xsi=
xsi:schemaLocation=
<!
<servlet>
<!
<servlet
<servlet
<!
<init
<param
<param
</init
<!
<init
<param
<param
</init
<!
<init
<param
<param
</init
<!
<init
<param
<param
</init
<!
<init
<param
<param
</init
<!
<init
<param
<param
</init
<!
<init
<param
<param
</init
<!
<init
<param
<param
</init
<!
<init
<param
<param
</init
</servlet>
<!
<servlet
<servlet
<url
</servlet
<welcome
<welcome
<%@ page language=
pageEncoding=
//點擊切換驗證碼
function changeVerifyCode(img){
img
}</script></head><body>
<p>
<form action=
<table>
<tr>
<td>
</td>
<td>
<img src=
</td>
</tr>
<tr>
<td>
請輸入驗證碼
</td>
<td>
<input type=
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type=
</td>
</tr>
</table>
</form>
</body></html>
package cn
public void doGet(HttpServletRequest request
throws ServletException
response
response
response
PrintWriter out = null;
try {
//響應數據
String resultData;
//獲取傳過來的驗證碼
String verifyCode = request
System
if(verifyCode==
resultData =
}else {
//獲取kaptcha生成存放在session中的驗證碼
String kaptchaValue = (String) request
//比較輸入的驗證碼和實際生成的驗證碼是否相同
if(kaptchaValue = null || kaptchaValue =
resultData =
}else {
resultData =
}
}
out = response
out
out
}catch(Exception e) {
e
}finally {
if(out != null) {
out
}
}
}
}
<!
<servlet>
<servlet
<servlet
</servlet>
<servlet
<servlet
<url
</servlet
<%@ page language=
pageEncoding=
//點擊切換驗證碼
function changeVerifyCode(img){
img
}
//提交
function doSubmit() {
var verifyCodeValue = $(
if(verifyCodeValue
alert(
}else {
//提交前先異步檢查驗證碼是否輸入正確
var =
$
type:
url:
success:function(returnData){
if(returnData!=
alert(
}else {
//驗證碼正確
//……
}
}
error:function(e){
alert(e)
}
})
}
}</script></head><body>
<p>
<form action=
<table>
<tr>
<td>
</td>
<td>
<img src=
</td>
</tr>
<tr>
<td>
請輸入驗證碼
</td>
<td>
<input type=
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type=
</td>
</tr>
</table>
</form>
</body></html>
From:http://tw.wingwit.com/Article/program/Java/hx/201311/27179.html