2
votes

Here is my jsp code:

<s:form method="POST" action="foo/bar">
    <s:submit value="Update"/>
    <s:submit value="Reverse" action="foo/bar/reverse"/>
</s:form>

jsp page Struts2 theme is simple.

Here is my struts mapping:

    <action name="foo/bar"
        class="my.package.BarAction">
        <result>/foo/bar.jsp</result>
    </action>

    <action name="foo/bar/reverse"
        class="my.package.BarAction"
            method="reverse">
        <result>/foo/bar.jsp</result>
    </action>

So when I first go on page, url in browser address string is localhost:myapp/foo/bar.action when I click submit button, page reloads, url becomes the same. But when I click on "reverse" button, page reloads, but url still the same. I think url should change to localhost:myapp/foo/bar/reverse.action, as "reverse" button is mapped on that action. So why doesn't url in browser address input change? Not that I wanted url in address string to change on "reverse" pressed, but it seems to be reasonable to happen and I'm curious why it doesn't.

Struts version is 2.13.5.1

EDIT1:

I checked in google dev tools, and when I press "reverse" button the request is sent to "http://localhost/myapp/foo/bar.action", not to "http://localhost/myapp/foo/bar/reverse.action"

EDIT2:

I tried removing action mapping for foo/bar/reverse action and now I get 404 error when I press "reverse" button, saying that there is no action mapped for action name foo/bar/reverse. Also looking at the request I found that the following form data is passed in the request: action:foo/bar/reverse=Reverse

So it appears that for the client, struts2 behaves as if request was sent to foo/bar.action (which is where it is actually sent), but later struts executes a different action.

EDIT3:

I changed result in struts mapping to foo/blabla.jsp for foo/bar/reverse action and now after I press reverse button, i get contents of blabla.jsp but url in browser is still the same.

I guess, it appears that it's just how Struts2 work.

1
Please show your struts.xml: constants, packages etcAndrea Ligios
@AndreaLigios no constans, package name = foo, extends struts-defaultdhblah
It is how S2 works. The action from submit won't be in url bar.Aleksandr M

1 Answers

1
votes

From the Struts2 documentation:

Action Names With Slashes

If your action names have slashes in them (for example,

<action name="admin/home" class="tutorial.Admin"/>

) you need to specifically allow slashes in your action names via a constant in the struts.xml file by specifying

<constant name="struts.enable.SlashesInActionNames" value="true"/>. 

See JIRA Issue WW-1383 for discussion as there are side effects to setting this property to true.