1

Currently I am working in Struts migration task from 1.x to 2.x. The major problem I am facing is that change in URL pattern.

In Struts 1, we use url pattern as below.

Note: multiple methods resides in each action class

https://<host-name>/xxx.do?method=begin

After struts 2, we are following below url pattern

https://<host-name>/xxx_begin.action

struts.xml:(used wildcard mapping)

<action name="xxx_*" method ="{1}" class = "foo.Myaction"><result name="success"> myjsp.jsp</result></action>

Question:

Is there any way to achieve the same url pattern as mentioned for Struts 1 in Struts 2?

Since its very big project, it is very complicated to update each and every place where the invocation happens. I have searched through many sources and found, it is easy to configure .action extension to .do extension by simply adding the below config in struts.xml

<constant name="struts.action.extension" value="do"/>

But how to achieve the method invocation as same as Struts 1.

If there is solution, also please mention how to add the action mapping in struts.xml?

Roman C
  • 49,761
  • 33
  • 66
  • 176

1 Answers1

0

Struts actions are mapped using the ActionMapper. You can use different action mapper class configured to the application. The action mapper used by default is not able to map URLs to actions the same way you did in Struts 1. Some action mappers are available via plugins but it's not possible to map parameters to the action. Only action name and namespace are mapped.

It is important that before you write your own action mapper to understand What is the role of the action mapper in Struts 2 and its scope.

There's also special parameter used by DMI, which is using a method prefix parameter name. If you find a way how to change the parameter to use its value as a name and add a method: prefix. The documentation said that a method prefix can be somehow overridden.

With method-prefix, instead of calling baz action’s execute() method (by default if it isn’t overridden in struts.xml to be something else), the baz action’s anotherMethod() will be called.

Struts 2 can be extended via providing a custom action mapper.

Roman C
  • 49,761
  • 33
  • 66
  • 176