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

前端 未结 2 1005
春和景丽
春和景丽 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

    
       
          
          
       
    
    

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

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

    hope this helps you.

提交回复
热议问题