问题
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