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>
An ActionForward represents a destination to which the controller, RequestProcessor, might be directed to perform a RequestDispatcher. forward or HttpServletResponse. sendRedirect to, as a result of processing activities of an Action class.
Create Multiple Actions struts2; import com. opensymphony. xwork2. ActionSupport; class MyAction extends ActionSupport { public static String GOOD = SUCCESS; public static String BAD = ERROR; } public class HelloWorld extends ActionSupport { ... public String execute() { if ("SECRET".
Q 13 - Which of the following is true about action tag in struts. xml? A - We define action tags corresponds to every URL we want to access.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With