Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts 2 - Mapped Actions working with any URL

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>
like image 268
A. Cusano Avatar asked Dec 07 '11 23:12

A. Cusano


People also ask

How does Struts action forward work?

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.

What are different ways to create action classes in Struts2?

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

Which of the following is true about action tag in struts xml?

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.


1 Answers

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

like image 82
Dave Newton Avatar answered Sep 27 '22 22:09

Dave Newton