为避免重复提交 使用 struts的 token为什么System.out.println(this.isTokenValid(request));
打印出来的是 false呢??
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");
}
}
打印出来的是 false呢??
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");
}
}
解决方案 »
- 求算法,上一个说的不是很详细。急!各位大侠帮忙!
- spring配置文件中biz层的bean太多显得臃肿,如何优化?
- hibernate建表问题
- 无原因向sun送分
- 有关数据库中文字段问题?
- 在struts中,如何在iterator标签中显示hibernate一对多关系中set内容?
- 很奇怪的问题,RESIN在服务器上可以访问,到外网就不能访问了
- 四个J2EE讨论群,都升级为256M高级群,分别讨论STRUTS EJB Servlet XML/JSP邀请各位豪杰加入,一起共享代码和教程
- java 数据库问题
- JB9改变字体后,鼠标指示位置出现错误
- 下面是我自己做的小程序,但是我不想用println换行,我想用\n换行,怎样修改我的程序。
- 蛋疼的面试题---------------->如何理解面向对象<----------------------------------------
会在shezhiToken的页面加 一个 hidden的Token值, 是在shezhiToken跳转的页面
而你的是在未跳转前就isTokenValid 这时候request里面没有Token
if(this.isTokenValid(request,true)){
System.out.println("=============执行方法了==============");
this.resetToken(request);
}
打印出的也是false,且不执行里面的内容呢?
具体情况如下:
项目是ssh结构,一个模块的跳转和提交在一个action的不同方法中,
link.do?method=postPo是进入提交页面,
link.do?method=editPo是提交信息,
在进入提交页面的方法中应用了saveToken(request);
saveToken(request);在提交方法中做判断,如果重复提交输出错误信息
if(!isTokenValid(request,true)){
System.out.println("//////////////////////");
ActionMessages error = new ActionMessages();
saveErrors(request, error);
return new ActionForward("/link.do?method=postPo");
}
else{
//省略保存表单信息代码
resetToken(request);
}
结果一直进入到"提示重复提交的分支中",这是为什么