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

struts2_4_为Action属性注入值

2015-01-28 17:45 405 查看
Struts2为Action中的属性提供了依赖注入功能,在struts2的配置文件里,能够为Action中的属性注入值,属性必须提供setter方法。

1)employeeAction类:

public class employeeAction {
private String savePath;

public String getSavePath() {
return savePath;
}

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

public String execute() {
return "success";
}
}


2)struts.xml文件:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<package name="package" namespace="/test"
  extends="struts-default">
<action name="empl" class="struts.employeeAction"
  method="execute">
  <!-- 为要注入值得属性注入值-->
<param name="savePath">zhuRu</param>
<result name="success">/index.jsp</result>
</action>
</package>
</struts>

3)index.jsp文件:

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