【问题标题】:Struts2 Convention Plugin Action UrlStruts2 Convention Plugin Action Url
【发布时间】:2012-03-29 05:10:37
【问题描述】:

我正在使用 struts2-convention-plugin 2.3.1.2。

   <constant name="struts.ui.theme" value="simple" />
   <constant name="struts.convention.default.parent.package" value="qqq"/>
   <constant name="struts.convention.package.locators.basePackage" value="zzz.yyy.xxx.action"/>
   <constant name="struts.enable.SlashesInActionNames" value="true"/>
   <constant name="struts.mapper.alwaysSelectFullNamespace" value="true"/>

   <package name="qqq" extends="struts-default" namespace="/">
       <!--
         Some package configurations
       -->
   </package>

struts2.xml配置如上。

  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
    <init-param>
      <param-name>actionPackages</param-name>
      <param-value>zzz.yyy.xxx.action</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>*</url-pattern>
  </filter-mapping>

web.xml如上,tomcat的上下文根为/foo。

问题

我把 LoginAction 放到了 zzz.yyy.xxx.action 包中, 并部署了应用程序,我得到了以下结果。

  1. localhost:8080/foo/login -> 好的
  2. localhost:8080/foo/bar/login -> 好的
  3. localhost:8080/foo/bar/baz/login -> 好的

我有点尴尬,因为这种行为不是我想要的。 我只想允许第一种情况。 我该怎么办?

【问题讨论】:

  • 我相信(不确定)这是由于 S2 具有的命名空间回退机制,但这只是一个想法,我自己对这个插件没有什么经验

标签: java struts2


【解决方案1】:

在“src”文件夹中创建一个名为 struts.properties 的文件。然后将下面的行添加到它。

struts.convention.action.suffix = Controller

【讨论】:

    猜你喜欢
    • 2020-01-24
    • 2010-12-24
    • 2017-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多