Struts2 - 在操作后未呈现页面时如何过滤(使用拦截器)页面

发布于 2024-10-07 13:20:40 字数 129 浏览 0 评论 0原文

我想知道(在 Struts2 上)是否可以将拦截器应用于单个 jsp 页面。例如:当我第一次加载我的应用程序时,我只是调用一个jsp(没有任何操作)。我知道如何在操作之前/之后放置拦截器,但是对于 JSP 来说?是否可以?

干杯

I would like to know (on Struts2) if 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

撩动你心 2024-10-14 13:20:40

好吧,struts 仅适用于操作,因此不可能在没有操作的情况下应用拦截器,但是我认为您可以实现您想要的效果:

在 struts.xml 文件中,您可以将操作定义为:

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

因此“textAction”呈现 myjsp。 jsp... 查看 struts 文档,您可以在包级别设置拦截器(如果包中只有一个操作,您将获得所需的行为),或者您甚至可以逐个操作地指定拦截器堆栈。

如果您想做更少的工作...您应该将 struts2-conventions-plugin 添加到您的类路径中。有了它,您就可以在很大程度上避免使用 struts.xml。

所以你不能摆脱这个动作,每个请求都应该是一个动作...但是你不必为每个动作创建一个类,并且使用约定插件,你甚至不需要更新你的 struts.xml只需放入jsp即可。如果没有 struts.xml 或在那里注释类,应用自定义拦截器将是一个挑战。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文