读书人

传智Struts2札记(5)为Action的属性注

发布时间: 2012-11-11 10:07:57 作者: rapoo

传智Struts2笔记(5)为Action的属性注入值
Struts2为Action中的属性提供了依赖注入功能,在struts2的配置文件中,我们可以很方便地为Action中的属性注入值。注意:属性必须提供setter方法。

public class HelloWorldAction{private String savePath;public String getSavePath() {return savePath;}public void setSavePath(String savePath) {this.savePath = savePath;}       ......}

<package name="itcast" namespace="/test" extends="struts-default"><action name="helloworld" ><param name="savePath">/images</param><result name="success">/WEB-INF/page/hello.jsp</result></action></package>

上面通过<param>节点为action的savePath属性注入“/images”

读书人网 >软件架构设计

热点推荐