您的位置:首页 > 编程语言 > Java开发

Struts 依赖注入

2016-07-05 10:10 316 查看
Struts2 为 Action 中的属性提供了依赖注入功能,在 Struts.xml 中配置。但是该属性必须提供 setter 方法。

在HelloWorldAction中

public class HelloWorldAction{
private String savePath;

public String getSavePath(){
return savePath;
}

public void setSavePath(String savePath){
this.savePath = savePath;
}
}


在 struts.xml 中:
<package name="itcast" namespace="/test" extends="struts-default">
<action name="helloword" class="……">
<param name="savePath">/images</param> ## 属性注入,注入值为 /images
<result name="success">/1.jsp</result>
</action>
</package>

在 6.jsp 中
<body>
${savePath}
</body>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: