STRUTS2拦截器问题 在执行完Action之后进行拦截没有什么意义啊,因为这种你完全可以在Action里面自己处理。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这样可以去掉重复代码, 不用每一个ACTION都写拦截器中的代码 我一直不明白这一段代码为什么是执行完JSP后, 再去执行拦截器的after方法struts2是怎么做到呢? 1. public abstract class AroundInterceptor extends AbstractInterceptor { 2. 3. /* (non-Javadoc) 4. * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation) 5. */ 6. @Override 7. public String intercept(ActionInvocation invocation) throws Exception { 8. String result = null; 9. 10. before(invocation); 11. // 调用下一个拦截器,如果拦截器不存在,则执行Action 12. result = invocation.invoke(); 13. after(invocation, result); 14. 15. return result; 16. } 17. 18. public abstract void before(ActionInvocation invocation) throws Exception; 19. 20. public abstract void after(ActionInvocation invocation, String resultCode) throws Exception; 21. 22. } 使用PreResultListener就可以实现了相应拦截器的方法中注册监听:invocation.addPreResultListener(new XXListener());正常来讲,before是在之前拦截,after是在调用action之后且执行了result后才拦截如果使用拦截器注解就还会有一个BeforeResult,也就是在调用action之后且没有执行result的时候被拦截也就相当于上面的PreResultListener // 添加监听器PreResultListener invocation.addPreResultListener(new PreResultListener() { public void beforeResult(ActionInvocation invocation, String resultCode) { System.out.println(resultCode); // 对返回的代码做你要做的事 } });大概就是这样~~~ 有validate 验证一下。然后再执行Action 他是想在Action之后在拦截一下~~~~ 关于BufferedImage创建大小的问题 java怎样写数据到表格? 做OA时,公文是保存进数据库里好,还是以文件形式保存在硬盘上好? 关于得到一个范围内的随机数 关于直线,及直线如何被选中的问题,100分紧急求助!!! 编码问题请指教 请教 屁股着火了,请各位大哥帮帮小弟。高分加提成 在一个文件中查找一字符串,在该串后面插入一字符串该怎样处理? Java数组问题 各位老师帮忙看下我分析的对不对??谢谢。 java连接mssql 2000问题
struts2是怎么做到呢?
1. public abstract class AroundInterceptor extends AbstractInterceptor {
2.
3. /* (non-Javadoc)
4. * @see com.opensymphony.xwork2.interceptor.AbstractInterceptor#intercept(com.opensymphony.xwork2.ActionInvocation)
5. */
6. @Override
7. public String intercept(ActionInvocation invocation) throws Exception {
8. String result = null;
9.
10. before(invocation);
11. // 调用下一个拦截器,如果拦截器不存在,则执行Action
12. result = invocation.invoke();
13. after(invocation, result);
14.
15. return result;
16. }
17.
18. public abstract void before(ActionInvocation invocation) throws Exception;
19.
20. public abstract void after(ActionInvocation invocation, String resultCode) throws Exception;
21.
22. }
相应拦截器的方法中注册监听:invocation.addPreResultListener(new XXListener());正常来讲,before是在之前拦截,after是在调用action之后且执行了result后才拦截如果使用拦截器注解就还会有一个BeforeResult,也就是在调用action之后且没有执行result的时候被拦截
也就相当于上面的PreResultListener
// 添加监听器PreResultListener
invocation.addPreResultListener(new PreResultListener() {
public void beforeResult(ActionInvocation invocation, String resultCode) {
System.out.println(resultCode);
// 对返回的代码做你要做的事
} });
大概就是这样~~~