圖片驗證在有關注冊和發表留言經常用到
代碼如下:
<%@ page autoFlush="false" import="java
<%@ page import="" contentType="text/html; charset=gb
<%
String chose="
char display[]={
Random rand=new Random();
for(int i=
{
temp=chose
display[i*
ran[i]=temp;
}
String random=String
session
%>
<%
out
response
response
response
response
int width=
BufferedImage image = new BufferedImage(width
Graphics g = image
//以下填充背景顏色
g
g
//設置字體顏色
g
g
g
ServletOutputStream outStream = response
JPEGImageEncoder encoder =JPEGCodec
encoder
outStream
%>
代碼如下:
<%@ page contentType="text/html; charset=gb
<%
String num=request
String random=(String)session
if(num!=null&&random!=null)
{
if(!num
{
out
out
//response
}
else
{
out
}
}
%>
<html>
<head>
<title>圖片驗證</title>
<meta http
</head>
<body>
<form action="img
<table>
<tr>
<td>
<input type="text" name="num" size=
</td>
<td>
<img src="random
</td>
</tr>
</table>
<input type="submit" value="OK">
</form>
</body>
</html>
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19860.html