In Struts1, how to use set-property tag inside action tag?

早过忘川 提交于 2019-12-01 13:03:20

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!