概述
- struts2爲Action中的屬性提供了依賴注入功能
- 在struts2的配置文件中,咱們能夠很方便地爲Action中的屬性注入值。注意:屬性必須提供get,set方法。
配置
<action name="helloworld" class="com.liuyong666.action.HelloWorldAction">
<param name="savePath">/resource</param>
<result name="success">/WEB-INF/page/hello.jsp</result>
</action>
對應類中的變化
public class HelloWorldAction{
private String savePath;
public String getSavePath() {
return savePath;
}
public void setSavePath(String savePath) {
this.savePath = savePath;
}
......
}
好處
- 上面經過<param>節點爲action的savePath屬性注入「/resource」,能夠再hello.jsp頁面獲取/resource
- 爲action注入屬性值應用於常常換的變量,這樣不用更換源代碼。
- 好比該變量爲使用該軟件公司的名稱
