当前位置: 代码迷 >> Java Web开发 >> struts2为action属性注入值得时候为什么调用两次set方法?解决方法
  详细解决方案

struts2为action属性注入值得时候为什么调用两次set方法?解决方法

热度:180   发布时间:2016-04-17 01:02:46.0
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
  相关解决方案