session和验证码不同步的问题,高手指点下,
为什么我session获取的取总比验证图片里的慢一步啊,高手指点下,加分!~
我的验证码用servlet写的,代码:
package checkDraw;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.sun.image.codec.jpeg.*;
import java.awt.*;
import com.sun.image.codec.jpeg.*;
import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.geom.GeneralPath;
import javax.swing.*;
import java.math.*;
public class checkServlet
extends HttpServlet {
//Process the HTTP Get request
public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException,
IOException {
response.setContentType(request.getContentType());
response.setContentType( "image/jpeg "); //必须设置ContentType为image/jpeg
response.setHeader( "Pragma ", "No-cache ");
response.setHeader( "Cache-Control ", "no-cache ");
response.setDateHeader( "Expires ", 0);
HttpSession session = request.getSession(true);
int length = 4; //设置默认生成4个数字
Date d = new Date();
long lseed = d.getTime();
Random r = new Random(); //设置随机种子
if (request.getParameter( "length ") != null) {
try {
length = Integer.parseInt(request.getParameter( "length "));
}
catch (
NumberFormatException e) {
}
}
StringBuffer str = new StringBuffer();