5

我正在使用 Struts2 创建一个 Web 应用程序,但我在使用任何 url 的映射操作时遇到问题。

在我的 struts.xml 文件中,我配置了一个名称空间为“/registration”的包,其中包含一些操作,主要的是“注册”。我的应用程序的上下文根是“app/test”。

要访问注册表单,我可以转到“localhost:8080/app/test/registration/register.action”,它会加载我的表单并且效果很好。

但是,如果在命名空间之后的 URL 中添加任何内容,例如“localhost:8080/app/test/registration/arbitrary/text/here/register.action”,表单仍然会加载。

我想防止这种情况发生,以便您只能访问正确的 URL 表单。我在 struts.xml 和 web.xml 中尝试了许多不同的配置选项,但均无济于事,而且我无法在网上轻松找到有关此问题的知识。

任何帮助将不胜感激,谢谢!

struts.xml

<struts>
    <package name="myPackage" namespace="/registration" extends="struts-default">
        <result-types>
            <result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult"/>
        </result-types>
        <action name="register" class="edu.uconn.test.action.RegistrationAction" method="input">
            <result name="input" type="tiles">/register.tiles</result>
        </action>
    </package>
</struts>
4

1 回答 1

7

Set the struts.mapper.alwaysSelectFullNamespace constant to true:

<constant name="struts.mapper.alwaysSelectFullNamespace" value="true" />

This may have unintended consequences when leveraging S2's support for arbitrary parameters in URLs (e.g., wildcarding, regex pattern matching).

于 2011-12-08T01:06:33.580 回答