开发者

Struts2 - How to filter (with Interceptors) a page when it isn't rendered after an Action

I would like to know (on Struts2) i开发者_如何学JAVAf is possible to apply an Interceptors to a single jsp page. for example : when i load for the first time my application, i just call a jsp (no one action). I know how to put a interceptor before/after an action, but for a JSP? Is it possible?

Cheers


Well struts only works on actions so it is not possible to apply an interceptor without an action however I think you can achieve the effect that you want:

In your struts.xml file you can define an action as:

    <action name="textAction">
        <result>myjsp.jsp</result>
    </action>

So 'textAction' renders myjsp.jsp... Look at the struts documentation you can set interceptors at the package level (if you only have one action in the package you get the behavior you want) or you can even specify the interceptor stack on a action by action basis.

If you want to do even less work... You should add the struts2-conventions-plugin to your class path. With it in place you can avoid using struts.xml for the most part.

So you can't get rid of the action, every request should be an action... But you don't have to create a class for every action and with the convention plugin you don't even need to update your struts.xml just drop in the jsp. Without struts.xml or annotating a class there it would be challenging to apply your custom interceptor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜