struts 拦截器 使用

来源:互联网 发布:python教程3.6.2 编辑:程序博客网 时间:2024/05/22 15:51
在action上加拦截器的时候,一定要先加
@InterceptorRef("defaultStack")

不然会抛异常,哪个异常我忘记了。。。

下面是防止重复提交的过滤器
当然页面中要加<s:token></s:token>
@Action(interceptorRefs = {@InterceptorRef("defaultStack"), @InterceptorRef("token")},value = "quickReply", results = {@Result(name = Constants.SUCCESS, location = "/post.jsp")})


//token验证失败public static final String INVALIDTOKEN = "invalid.token";



在整个action的class中加过滤器
@Scope("prototype")@Controller@Results( { @Result(name = Constants.SHOW_ERROR, location = "/errorMessage.jsp"),@Result(name = Constants.INVALIDTOKEN, location = "/tokenErrMsg.jsp")})@ParentPackage("default")@InterceptorRefs(value = {@InterceptorRef("defaultStack"), @InterceptorRef("sessionTimeoutInterceptor") })@ExceptionMappings( {@ExceptionMapping(exception = "java.lang.Exception", result = Constants.SHOW_ERROR),@ExceptionMapping(exception = "com.community.exception.DataAccessException", result = Constants.SHOW_ERROR) })