Struts 2 - Mapped Actions working with any URL

无人久伴 提交于 2019-11-29 21:45:51

问题


I am creating a web app with Struts2, and I am having an issue with the mapped actions working with any url.

In my struts.xml file, I have configured a package with a namespace of "/registration" with a few actions, with the main one being "register". The context root of my app is "app/test".

To access the registration form, I can go to "localhost:8080/app/test/registration/register.action" and it loads up my form and works great.

However, if anything is added to the URL after the namespace, such as "localhost:8080/app/test/registration/arbitrary/text/here/register.action", the form is still loaded up.

I would like to prevent this from happening, so that you can only access the form the proper URL. I have tried many different configuration options in struts.xml and web.xml to no avail, and I cannot find knowledge on this issue easily on the web.

Any help will be appreciated, thanks!

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>

回答1:


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).



来源:https://stackoverflow.com/questions/8424215/struts-2-mapped-actions-working-with-any-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!