Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mapping an struts2 action based on querystring, rather than path name

Is there a way to configure struts 2, so that the dispatcher will use the querystring to map the action to invoke?

For example, in the link below, I would like to invoke action blah, not action foo.

http://domain:port/myapp/foo.do?someparameter=blah

Thanks.

like image 539
James Young Avatar asked Dec 07 '25 09:12

James Young


2 Answers

I do not think that is possible with any of the default mappers.

It wouldn't be that bad to create an Interceptor that is configured for your foo action that checks the value of someparameter, and either chains or redirects to your blah action.

like image 104
Jeremy Avatar answered Dec 09 '25 21:12

Jeremy


+1 Jeremy: That can do the magic else if you don't want to create an action just create a kinda dispatcher action which will dispatch your request to certain action based on the value of Query String

For e.g

Foo action execute();

if (querystring="test") {
    setActionName("Test");
    return "next";
}

Based on these control string, you can forward request to certain action.

<result name="next" type="redirectAction">${actionName}</result>
like image 39
Umesh Awasthi Avatar answered Dec 09 '25 21:12

Umesh Awasthi