Struts 2.3 with multiple submit tags with action attribute

This is something very simple that works great with Struts 2.1.x. But we recently upgraded to 2.3.15.2, and it broke. Basically we have a form (in fact, many forms) with several views:

<s:form> <s:submit action="save" /> <s:submit action="resetPassword" /> </s:form> 

If I stick with the action in the tag, all is well. But if instead it is in the tag, I get 404 error. And this is the same action!

I debugged and found that when you use the action attribute in the tag generated by html:

 <input type="submit" name="action:save"> <input type="submit" name="action:resetPassword"> 

Presumably, Struts should take this "action" prefix and say "A-ha! This action!". and execute it. And this is something like that. Or at least trying. I found that at a very low level, the DefaultActionMapper.handleSpecialParameters () method goes through all the parameters and tries to create a ParameterAction for each of them, and if it is not null, it is executed. Most parameters generate an “null” attribute attribute, but not an “action:” parameter.

In the docs, I found this in ParameterAction:

 Defines a parameter action prefix. This is executed when the configured prefix key is matched in a parameter name, allowing the implementation to manipulate the action mapping accordingly. For example, if the "action:foo" parameter name was found, and a ParameterAction implementation was registered to handle the "action" prefix, the execute method would be called, allowing the implementation to set the "method" value on the ActionMapping 

So, what he does is set the result of the comparison with the new ServletDispatcherResult named Action:

 mapping.setResult(new ServletDispatcherResult(actionName)); 

On the other hand, when an action is specified in the s: form tag, the result of the match is null.

So, when we finally get down to Dispatcher.serviceAction ():

 if (mapping.getResult() != null) { Result result = mapping.getResult(); result.execute(proxy.getInvocation()); } else { proxy.execute(); } 

So, when the action is indicated in the tag, proxy.execute () is called, which simply calls the Action / method itself. What should happen! But when the action is indicated in the tag, since the display has a result, the proxy call is passed to result.execute (), which calls ServletDispatcherResult ... and in the end I get 404.

This seems to be a lot of work, just to get a few submit buttons with valid action attributes. Is this a known issue for Struts 2.3? Do I need to implement the ParameterAction parameter for the "action" prefix, as indicated in the docs?

EDIT

Well, a known bug discovered just a few days ago. In the meantime, I can either lower it to 2.3.15.1, or use the attribute “method”, and not the attribute “action”.

Hopefully this will be fixed soon ...

+7
jsp forms struts2 dmi
source share
2 answers

this is b / c in struts2.3.16.

Disables action support: prefix

default struts.mapper.action.prefix.enabled = false

set

 <constant name="struts.mapper.action.prefix.enabled" value="true"/> 

in struts.xml

Internal changes to struts2-core 2.3.16

Action: and method: default prefixes are excluded and changed to check excludeParams first and then accept Params in ParametersInterceptor

+5
source share

It is assumed that it is in the process of correction for 2.3.15.3.

Specific Jira:

https://issues.apache.org/jira/browse/WW-4204

+2
source share

All Articles