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

前端 未结 2 980
春和景丽
春和景丽 2021-01-16 09:33

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 ex         


        
相关标签:
2条回答
  • 2021-01-16 10:09

    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.

    0 讨论(0)
  • 2021-01-16 10:12

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

    0 讨论(0)
提交回复
热议问题