解决方案 »

  1.   

    session不同步导致的,你是异步登录操作,那么获取session也应该异步。。
      

  2.   

    呃,上周五的时候又改成Extjs做了,还是取不到session里的验证码的值。EXt的验证码代码段:new Ext.Panel(
    {
    baseCls : "x-plain",
    layout : 'column',
    width : 290,
    height : 38,
    items : [
    {
    layout : "form",
    columnWidth : .7,
    labelWidth : 97,
    items : [ {
    xtype : "textfield",
    width : 90,
    fieldLabel : "Codingss",
    name : "image",
    allowBlank : true,
    } ],
    },
    {
    columnWidth : .3,
    html : "<a href='javascript:void(0)'><img border='0' src='pages/image.jsp' id='image'  onClick='to('pages/login.jsp');'></a>",
    } ],
    }) ],
    buttons : [
    {
    text : "Submit",
    type : "submit",
    handler : function() {
    if (form1.form.isValid()) {
    form1.form
    .submit({
    waitMsg : "Loging......",
    url : "login.action",
    method : "post",
    success : function(
    form, action) {
    Ext.Msg
    .alert(
    "Tips",
    "LoginSuccess!");
    document.location = "index.jsp";
    },
    failure : function(
    form, action) {
    Ext.Msg
    .alert(
    "Tips",
    action.result.message);
    }
    });
    }
    }
    }  验证码存入session: // 将认证码存入SESSION
    session.setAttribute("rand",sRand);
    System.out.println("新的验证码"+sRand);
    // 图象生效
    g.dispose();
    OutputStream output=response.getOutputStream();
    // 输出图象到页面
    ImageIO.write(image, "JPEG", response.getOutputStream());
    output.flush();
    out.clear();
    out = pageContext.pushBody();
    action代码://String rand=(String)ServletActionContext.getRequest().getSession().getAttribute("rand");
    String rand=(String)ActionContext.getContext().getSession().get("rand");
      

  3.   

    呃,上周五的时候又改成Extjs做了,还是取不到session里的验证码的值。EXt的验证码代码段:new Ext.Panel(
                                            {
                                                baseCls : "x-plain",
                                                layout : 'column',
                                                width : 290,
                                                height : 38,
                                                items : [
                                                        {
                                                            layout : "form",
                                                            columnWidth : .7,
                                                            labelWidth : 97,
                                                            items : [ {
                                                                xtype : "textfield",
                                                                width : 90,
                                                                fieldLabel : "Codingss",
                                                                name : "image",
                                                                allowBlank : true,
                                                            } ],
                                                        },
                                                        {
                                                            columnWidth : .3,
                                                            html : "<a href='javascript:void(0)'><img border='0' src='pages/image.jsp' id='image'  onClick='to('pages/login.jsp');'></a>",
                                                        } ],
                                            }) ],
                            buttons : [
                                    {
                                        text : "Submit",
                                        type : "submit",
                                        handler : function() {
                                            if (form1.form.isValid()) {
                                                form1.form
                                                        .submit({
                                                            waitMsg : "Loging......",
                                                            url : "login.action",
                                                            method : "post",
                                                            success : function(
                                                                    form, action) {
                                                                Ext.Msg
                                                                        .alert(
                                                                                "Tips",
                                                                                "LoginSuccess!");
                                                                document.location = "index.jsp";
                                                            },
                                                            failure : function(
                                                                    form, action) {
                                                                Ext.Msg
                                                                        .alert(
                                                                                "Tips",
                                                                                action.result.message);
                                                            }
                                                        });
                                            }
                                        }
                                    }
      验证码存入session: // 将认证码存入SESSION
    session.setAttribute("rand",sRand);
                System.out.println("新的验证码"+sRand);
    // 图象生效
    g.dispose();
    OutputStream output=response.getOutputStream();
    // 输出图象到页面
    ImageIO.write(image, "JPEG", response.getOutputStream());
    output.flush();
    out.clear();
    out = pageContext.pushBody();action代码://String rand=(String)ServletActionContext.getRequest().getSession().getAttribute("rand");
                String rand=(String)ActionContext.getContext().getSession().get("rand");
      

  4.   

    怎么放的,还怎么取,用request.getSession().getAttribute("rand")
      

  5.   

    session.getAttribute("rand")呢?
      

  6.   

    我那段注释掉的代码//String rand=(String)ServletActionContext.getRequest().getSession().getAttribute("rand"); 就是之前用request取的,不过没有取到
      

  7.   

    session.setAttribute("rand",sRand);
                System.out.println("新的验证码"+sRand);
    这两句放到生成验证码最后面。
      

  8.   

    把那两句放到out = pageContext.pushBody();后面吗
      

  9.   

    这个和同步,异步没有关系 ,建议你装一个fiddler监控一下http的请求,这样分析起来会容易很多,另外补一下http协议相关的知识
      

  10.   

    你的ajax是不是跨域了, 跨域请求的时候, 服务器session会发生改变,所以session里面原来存储的验证码的值不存在了,也就为null了