将 struts.xml 与约定插件一起使用
这看起来应该很容易做到,但我只能让它发挥作用。我对 Struts 2.1 中的约定插件着迷。但是,我需要定义一些包级配置,例如新的拦截器堆栈和异常映射。我想为此使用 struts.xml 文件,但我无法获得与 struts.xml 包匹配的基于约定的包。我的 struts.xml 看起来像:
<struts>
<constant name="struts.convention.default.parent.package" value="default"/>
<package name="default" extends="struts-default">
</package>
<package name="root" namespace="/" extends="struts-default">
<action name="index">
<result>/index.jsp</result>
</action>
</package>
<package name="my.package.actions.myaccount" namespace="/myaccount" extends="struts-default">
<interceptors>
<interceptor name="authenticationInterceptor" class="my.package.interceptors.AuthenticationInterceptor"/>
<interceptor-stack name="secureStack">
<interceptor-ref name="authenticationInterceptor"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="secureStack"/>
</package>
</struts>
我的拦截器位于:
/src/my/package/拦截器
以及我的行动:
/src/my/package/actions/myaccount
This seems like it should be easy to do, but I just can make it work. I'm hooked on the convention plugin in Struts 2.1. However, I need to define some package-level configuration such as a new interceptor stack and exception mappings. I'd like to use the struts.xml file for this, but I can't get the convention-based packages matched to the struts.xml packages. My struts.xml looks like:
<struts>
<constant name="struts.convention.default.parent.package" value="default"/>
<package name="default" extends="struts-default">
</package>
<package name="root" namespace="/" extends="struts-default">
<action name="index">
<result>/index.jsp</result>
</action>
</package>
<package name="my.package.actions.myaccount" namespace="/myaccount" extends="struts-default">
<interceptors>
<interceptor name="authenticationInterceptor" class="my.package.interceptors.AuthenticationInterceptor"/>
<interceptor-stack name="secureStack">
<interceptor-ref name="authenticationInterceptor"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="secureStack"/>
</package>
</struts>
I have my interceptor in:
/src/my/package/interceptors
and my actions in:
/src/my/package/actions/myaccount
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了。我将上面的包的名称更改为“myaccount”
然后您可以通过注释将其添加到单个操作
中:或者通过将 package-info.java 文件添加到相应的目录(其中包括以下:
希望这可以节省其他人的时间!
I figured it out. I changed the name of the package above to just read "myaccount"
Then you can either add this to an individual action by annotation:
Or to all actions in the package by adding a package-info.java file to the appropriate directory which includes the following:
Hope this saves someone else some time!