How can I ensure all requests go through an interceptor stack?
When working in Struts2, it is just too easy to create a template and refer a URL to it without creating an associated Action. Struts2 merrily renders the template -- wh开发者_开发百科ich is fine in most cases, but not in our case: in order to ensure proper selection of a locale, we need all our requests go through a minimal interceptor stack.
We've been researching these two ways, both unsuccessfully:
Defining a "default action" which would be executed for any template which doesn't have an associated action.
Disabling the ability to render templates without an action -- this would force programmers to define actions for any template, which is a good solution too.
Thanks.
Maybe look into the wildcard mappings.
<action name="*" class="struts2you.examplelogin.BaseActionSupport">
<result name="success">{1}.jsp</result>
</action>
If you place something like this as the first action I think all your unmapped jsp will be run through the default interceptor stack which you can define in struts.xml
Then also place your jsp files under the WEB-INF directory to prevent direct access
When working in Struts2, it is just too easy to create a template and refer a URL to it without creating an associated Action.
Since Struts2 is an MVC framework, every request to it should invoke an action class and therefore go through an interceptor stack. I assume that you mean that you have JSPs that are not under WEB-INF and so they can be invoked directly via URL. That's generally a poor practice in the MVC world, as your JSPs should only represent the view layer. Place the JSPs somewhere under WEB-INF and all requests will be forced to go through an action, which will resolve your problem.
As for the choices, I would advocate creating explicit mappings for each of your templates.
精彩评论