Question

I want to pass a value in action when it is called using struts1 configuration file. I have create a form bean with following property

public class MyForm extends ActionForm {
    private String task;  

    public String getTask() {
        return task;
    }
    public void setTask(String task) {
        this.task = task;
    }
}

In struts-config.xml, I have defined form bean and action as below.

<form-bean name="myForm" type="demo.MyForm"></form-bean>
<action path="/myAction" name="myForm" type="demo.MyAction" scope="request">
    <set-property value="view" property="task" />
    <forward name="success" path="/result.jsp"></forward>
</action>

I am trying to run it in web sphere 6.1 with these configurations, it gives following exception

Deregister the mbean because of uncaught init() exception thrown by servlet action: javax.servlet.UnavailableException: Parsing error processing resource path file:/D:/workspaces/j-space/myProject/Web Content/WEB-INF/struts-config.xml
at org.apache.struts.action.ActionServlet.handleConfigException(ActionServlet.java:761)
at org.apache.struts.action.ActionServlet.parseModuleConfigFile(ActionServlet.java:744)
at org.apache.struts.action.ActionServlet.initModuleConfig(ActionServlet.java:689)
at org.apache.struts.action.ActionServlet.init(ActionServlet.java:356)
at javax.servlet.GenericServlet.init(GenericServlet.java:256)
....

I think I am missing something or using set-property tag in wrong way . Can anyone help?

Was it helpful?

Solution

Struts 1.3 DTD says

The "set-property" element is especially useful when a custom subclass is used with , , , or elements.

Create Subclass of ActionMapping with properties you would like to inclide

public class CustomActionMapping extends ActionMapping {

    private String task;

    public String getTask() {
        return task;
    }

    public void setTask(String task) {
        this.task = task;
    }
}

configure the custom action mapping in struts-config.xml

<action-mappings type="CustomActionMapping">
   <action path="/myAction" name="myForm" type="demo.MyAction" scope="request">
      <set-property value="view" property="task" />
      <forward name="success" path="/result.jsp"></forward>
   </action>
</action-mappings>

get the value of task in doGet/doPost method your Action class

CustomActionMapping cam = (CustomActionMapping) mapping;
String task = cam.getTask();

hope this helps you.

OTHER TIPS

Does your struts-config.xml follow the schema? See sample on http://struts.apache.org/1.3.10/index.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top