日期:2014-05-17  浏览次数:20679 次

struts2为action属性注入值得时候为什么调用两次set方法?
struts.xml
XML code

    <package name="itcast2" namespace="" extends="struts-default">
        <action name="helloworld" class="com.wjf.HelloWorldActio" method="execute">
            <param name="message">hello world</param>
            <result name="success">/myFirstStruts2.jsp</result>
        </action>
    </package>


Java code

action:
public class HelloWorldActio {

    private String message;
    
    public String getMessage(){
        System.out.println("调用了get方法");
        return this.message;
    }
    
    public void setMessage(String msg){
        System.out.println("调用了set方法");
        this.message = msg;
    }
    
    public String execute(){
        return "success";
    }
}


HTML code

jsp:
  <body>
    1、<s:property value="message"/>
  </body>


请求action时,控制台打印如下:
调用了set方法
调用了set方法
调用了get方法
请问为什么调用了两次set方法?

------解决方案--------------------
LZ execute()怎么写的?
------解决方案--------------------
http://www.iteye.com/topic/122566?page=2