4

I have an action in struts.xml:

<action name="reprint" class="reprintAction">
        <result name="success" type="redirectAction">
            <param name="actionName">reprint</param>
            <param name="namespace">/x</param>
            <param name="errorFlag">${errorFlag}</param>
            <param name="message">${message}</param>
        </result>
        <result name="view">/jsp/reprintOverview.jsp</result>
</action>

JSP:

<s:form action="reprint">
    <s:select name="selectedPdfPrinter" list="shopPdfPrinterList" listKey="deviceId" listValue="deviceId" theme="simple"/>
    <s:submit value="Print" theme="simple" method="shopPdfReprint"/>
</s:form>

with several form elements, all bound to one action. Each form has an individual submit-button with a distinct method (e.g. "shopPdfReprint"). Each method is mapped on to a method in the corresponding class.

Everything is working fine with Struts 2.2.3. But after Migration to 2.3.1 the method-mapping is not working. Instead calling the corresponding method (e.g. "shopPdfReprint"), only the execute() method of the class is invoked.

I've looked at the Docs, but unfortunately found no clue, how to adapt to 2.3.1

Anybody ran into this?

Roman C
  • 49,761
  • 33
  • 66
  • 176
Thomas Junk
  • 5,588
  • 2
  • 30
  • 43

2 Answers2

2

This happens because you have turned off DMI. The method attribute works with submit tag as before even after resent security fixes. Enable DMI using the constant

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

let me know if it didn't work.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • Tanks a lot! Unfortunately I could try it only tomorrow. I'll give you immediately feedback. I didn't change the configuration. I am wondering, that you mention "turning off DMI". Is there a different default-behaviour? – Thomas Junk Nov 18 '13 at 17:33
  • By default DMI is on, that allows to have a special syntax in URL to execute methods other than mapped to that URL and submit tag uses it. – Roman C Nov 18 '13 at 17:54
  • 1
    Yes! Thank you very much! Works like a charm. After you gave me the hint, I looked further for this issue. It really seems, that DMI is turned off by default for secuity reasons. If we weren't in a long term migration process to Spring MVC, I would now consider to switch. – Thomas Junk Nov 19 '13 at 08:13
0

If anyone is moving or working on Struts 2.5 then they don't have to map actions using struts.xml. Strtus 2.5 is annotation based so in action class developer can map multiple actions within in single class using annotation.

May be this link helpful from old struts versions to struts 2.5 version.

https://struts.apache.org/docs/struts-23-to-25-migration.html

Following is the simple demo code.

package com.stsh.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionSupport;
import com.stsh.intercepter.AuthRequired;

@ParentPackage(value="default")
@Namespace(value="/dashboard")
public class DashboardAction extends ActionSupport implements AuthRequired{

    private static final long serialVersionUID = 1L;

    @Action(value = "home", results = { @Result(name = "success", location = "dashboard.tiles", type = "tiles") })
    public String dashboard(){
        return "success";
    }
}