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

请教关于重复提交问题
为避免重复提交 使用 struts的 token

为什么System.out.println(this.isTokenValid(request));
打印出来的是 false呢??

Java code

public class CeshiToken extends DispatchAction {
    
    public ActionForward shezhiToken(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        this.saveToken(request);
        System.out.println("设置token============================");
        
        //为什么这一行打印出来的是false ?????
        System.out.println(this.isTokenValid(request)+"~~~~~~~~~~~~~~~~~~~~~");
        return mapping.findForward("shezhiToken");
    }
    
    public ActionForward zhixingFangfa(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        System.out.println(this.isTokenValid(request));
        if(this.isTokenValid(request,true)){
            
            System.out.println("=============执行方法了==============");
            this.resetToken(request);
        }
        System.out.println("返回去了");        
        return mapping.findForward("chonghuiyemian");
    }
}



------解决方案--------------------
this.saveToken(request);
会在shezhiToken的页面加 一个 hidden的Token值, 是在shezhiToken跳转的页面
而你的是在未跳转前就isTokenValid 这时候request里面没有Token
------解决方案--------------------
帮顶,顶顶顶顶顶顶顶顶顶