大概情况如下:
后台ImageCodeServlet类关键代码:
StringBuffer buffer = new StringBuffer();
for(int i = 0;i<4;i++){
this.grap.setColor(this.getColor());
String str = String.valueOf(this.basicStr.charAt(rand.nextInt(this.basicStr.length())));
buffer.append(str);
this.grap.drawString(str, (30*i)+5, 30);
}
HttpSession session = request.getSession();//生成验证码,并把验证码记录入session
session.setAttribute("randcode", buffer.toString());
try {
ImageIO.write(image, "JPEG", response.getOutputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
客户端ajax请求关键代码:
$.ajax({
type: "POST",
url: "xxxxxxxxx/LoginAction",
data: {
"login_data1" : tempNo,
"login_data2" : timer,
"login_data3" : temprandcode,
"login_data4" : sign,
"login_data5" : token
}, //数据
async: true, //异步
dataType: "json",
后台LoginAction类关键代码:
if(request.getSession(false)!=null){//这里request.getSession(false)为null
randCode = (String) request.getSession().getAttribute("randCode");
}
问题来了:为何在LoginAction里获取的session为null?求关注,求解答