简体   繁体   中英

struts2 interceptors and webservlets

Is it possible to use a Struts2 interceptor for a page that doesn't have an action associated with it? Trying to implement an interceptor so all users must login. Yet the other pages in my site are webservlets and do not rely on actions or struts. How can I achieve that? I don't really want to create actions and action classes just to use an interceptor.

Since you are using Struts2, you should use primarily Actions, that are thread-safe and that work through an Interceptor Stack.

You can use Servlets for particular cases only, not for the default flow. If you do that, you are not using the framework, so you can't expect using any of its mechanism like Interceptors.

You can by the way use a Filter (Interceptors are based on that technology), handling the thread-safety in the Servlets by yourself.

The question is: why ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM