0

I'm migrating my application from Struts1 to 2.5. All the navigation url is defined as per below :

../menumanager.do?method=adduser
../menumanager.do?method=deleteuser

In struts 1 we extend dispather action class and reading the method name from query parameter. Using action forward we are redirecting to particular method.

Is there any way in struts 2, we can define same action name in struts.xml and besed on method name in the url we will redirect to paricular method.

I tried below code. When I hit ../menumanager.do?method=adduser it is going to last method of action class.

<action name="menumanager" method="adduser" class="X.Action">
        <result name="login">Some JSP</result>
         <result name="logout">Some JSP</result>
    </action>

 <action name="menumanager" method="deleteuser" class="X.Action">
        <result name="login">Some JSP</result>
         <result name="logout">Some JSP</result>
    </action>
  • I think you are override your own definition. Take a look at link [enter link description here](https://stackoverflow.com/questions/24791793/struts2-can-an-action-name-be-repeated-in-the-struts-xml-using-the-same-action) – user11333952 Apr 09 '19 at 10:23
  • You should be more specific about method you used to map your actions. If you want to use wildcard mapping then [this](https://stackoverflow.com/a/48434820/573032) answer could help you. – Roman C Apr 09 '19 at 13:01
  • Action names must be unique. You can either use wildcard mappings, use an interceptor (or a filter, I suppose, but meh), or just handle it manually in the action method. – Dave Newton Apr 09 '19 at 14:26
  • is it possible to give action name as "menumanager.do?method=adduser". Does regex in action support ".?" special character. – user3842475 Apr 10 '19 at 06:04
  • @user special character is not supported as a part of the action name, see also https://stackoverflow.com/a/30727658/573032 – Roman C Apr 13 '19 at 13:45

0 Answers0