日期:2014-05-20  浏览次数:20689 次

验证码刷新后session当中保存的是上次的值!!!
登陆页面当中调用session取值:
Java code
    <%
    String ccode=(String)request.getSession().getAttribute("ccode");
    System.out.println("Jsp-->"+ccode);
 %>


form表单:
HTML code
<html:form action="jsp/user.do" method="post">
    用户ID:<html:text property="userid" onblur="checkUserName();"></html:text>
    <span id="userIdMessage" style="width:200px ; height:10px;"></span>
    <br>
    用户密码:<html:password property="userpwd" onblur="checkPassWord();"></html:password>
    <span id="pwdMessage" style="width:200px ; height:10px;"></span>
    <br>
    确认密码:<html:password property="confirmpwd" onblur="checkConfpwd();"></html:password>
    <span id="confpwdMessage" style="width:200px ; height:10px;"></span>
    <br>
    丢失密码提示问题:<html:text property="userques"></html:text>
    <br>
    丢失密码问题答案:<html:text property="userans"></html:text>
    <br>
    验证码:<html:text property="checkcode" onblur="checkCode();"></html:text>
    <img src="image.jsp">
    <input type="hidden" name="ccode" value="<%=ccode%>">    
    <span id="checkcodeMessage" style="width:200px ; height:10px;"></span>
    <br>
    <input type="hidden" name="status" value="register">
    <input type="hidden" name="type" value="1">
    <html:submit value="注册"></html:submit>
    <html:reset value="重置"></html:reset>
</html:form>



验证码生成代码主要就是:

Java code
// 将认证码存入SESSION
session.setAttribute("ccode",sRand);


问题:第一次到达页面,从session里面没有取到验证码值,以后刷新都是取到上次显示的值。


(注:我这个是struts+dwr做的,望高人指点迷津)

------解决方案--------------------
都是这样的,
你把两个页面分开用就可以了,就是把提交页和接收页面分开,
如果用一个页面的话,就在页面里判断一下是否是提交状态!
if( request.getMethod().equalsIgnoreCase("POST") == true )
------解决方案--------------------
应该是浏览器缓存的事儿,试试改成
HTML code
<img src="image.jsp?<%=Long.toString(System.currentTimeMillis(), 36)%>">

------解决方案--------------------
原因可能是验证码的还有没生成,你就在session当中拿了值,所以第一次就没有拿到。第二次~~~~~之后拿的就是上一次的值。。
你可另建一个servlet去session当中拿值试试。