锁定老帖子 主题:Struts2的拦截器总结
精华帖 (0) :: 良好帖 (0) :: 新手帖 (2) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-11-12
引用 这是为什么呢? 还是defaultStack有问题? 我这里只有遇到错误了才不会往下执行,这样执行也没意义,如果均是正确的,任然不会出现说是不会进myinterceptor的情况。 |
|
返回顶楼 | |
发表时间:2008-12-10
引用 当然在这里还需要指出一点,你安放的拦截器的顺序,其实也就是拦截器执行的顺序!但是拦截器,不只是在执行execute()方法之前要执行,
而且在execute()方法之后也要执行。给出如下两个拦截器说明: 1 public String intercept(ActionInvocation invoker) throws Exception { System.out.println("intercept1"); String result=invoker.invoke(); System.out.println("finish1"); return result; } 2 public String intercept(ActionInvocation invoker) throws Exception { System.out.println("intercept2"); String result=invoker.invoke(); System.out.println("finish2"); return result; } 在配置顺序也是一二,结果会输出什么呢? intercept1 intercept2 finish2 finish1 这里执行拦截器的过程是正着来的,回来的时候是反着的。就像你要进一个很多门的房间一样。 进去一个,开一个门,为了让自己能回来的方便一些,这个打开的门就不要关着了,当你把所有的门进去了后,然后回来,再逐个关门。 这样的过程就像是这个拦截器执行的过程。 很想知道你这个“而且在execute()方法之后也要执行”如何配置实现的!!! |
|
返回顶楼 | |
发表时间:2008-12-15
yiway 写道 很想知道你这个“而且在execute()方法之后也要执行”如何配置实现的!!! 你写个类似的拦截器,xml 中按照你所知道的配置 看看是什么效果 |
|
返回顶楼 | |
发表时间:2009-01-13
最后修改:2009-01-13
zhuxinyu 写道 yiway 写道 很想知道你这个“而且在execute()方法之后也要执行”如何配置实现的!!! 你写个类似的拦截器,xml 中按照你所知道的配置 看看是什么效果 http://struts.apache.org/2.x/docs/building-your-own-interceptor.html invocation.getInvocationContext().getSession().put("Greeting", greeting); String result = invocation.invoke(); //应该是在这里写Action调用结束之后的代码。 //不要直接使用return invocation.invoke();返回 //在这里就可以添加Action执行结束之后想要运行的代码了 return result; 上面代码的来源是:Struts2 CookBook One other thing that interceptors can do is execute code after the action has executed. To do that, just place code after the invocation.invoke() call. 这是那个页面的原话: 大体意思是:interceptor们可以做的另一件事,就是在Action执行之后,还可以执行一些代码。如果你也想那么做的话,只需要在 invocation.invoke()之后写上你的代码就行了。 |
|
返回顶楼 | |
发表时间:2009-01-14
wpsfly 写道 http://struts.apache.org/2.x/docs/building-your-own-interceptor.html invocation.getInvocationContext().getSession().put("Greeting", greeting); String result = invocation.invoke(); //应该是在这里写Action调用结束之后的代码。 //不要直接使用return invocation.invoke();返回 //在这里就可以添加Action执行结束之后想要运行的代码了 return result; 上面代码的来源是:Struts2 CookBook One other thing that interceptors can do is execute code after the action has executed. To do that, just place code after the invocation.invoke() call. 这是那个页面的原话: 大体意思是:interceptor们可以做的另一件事,就是在Action执行之后,还可以执行一些代码。如果你也想那么做的话,只需要在 invocation.invoke()之后写上你的代码就行了。 恩,没错啊,我当初学习这个东西,也没看什么资料,不过链接真的还不错。感谢中。我也会借这个链接补充一下我的理论知识。 我在文中是为了说明逐个调用拦截器链中 finish1 和 finish2的顺序,那个先执行也在这体现了invocation.invoke();是调用下一个拦截器. |
|
返回顶楼 | |