在jsp页面的form中,添加

<s:token></s:token>

 然后在提交的action类中

 

@SuppressWarnings("unchecked")
@Scope("prototype")
@Controller
@Results( {
@Result(name = Constants.SHOW_ERROR, location = "/community/errorMessage.jsp"),

@Result(name = "timeout", location = "/community/timeoutMsg.jsp") })
@ParentPackage("default")
@InterceptorRefs(value = { @InterceptorRef("defaultStack"),
@InterceptorRef("checkCookieInterceptor") })
// , , @InterceptorRef("checkCookieInterceptor"),
// @InterceptorRef("sessionTimeoutInterceptor")
@ExceptionMappings( {
@ExceptionMapping(exception = "java.lang.Exception", result = Constants.SHOW_ERROR),
@ExceptionMapping(exception = "com.community.exception.DataAccessException", result = Constants.SHOW_ERROR) })

 添加发现重复提交后,返回的页面

@Result(name = Constants.INVALIDTOKEN, location = "/community/tokenErrMsg.jsp"),

 

然后在action方法中添加:

@Action(interceptorRefs = {@InterceptorRef("token")},
value = "quickReply", results = {
@Result(name = Constants.SUCCESS, type = "redirect", location = "showPostsById.action?fpid=${fpid}&anchor=${anchor}&pageNo=${pageNo}"),
//@Result(name = Constants.FAILURE, type = "chain", location = "showPostsById")
@Result(name = Constants.FAILURE, type = "redirect", location = "showPostsById.action?fpid=${fpid}&anchor=${anchor}&pageNo=${pageNo}&msgid=${msgid}&sid=${sid }")
})

 

这样就可以了,但是这样就会跳转到一个提示重复提交的页面,不大友好。

 

可以用tokenSesion来解决。

同样在jsp的form中添加

<s:token></s:token>

然后在action方法上加

interceptorRefs = {@InterceptorRef("tokenSession")},

 

 

这样就可以了。