概述

  • 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;
  	}
       ......
}

好处

  • 上面通过节点为action的savePath属性注入“/resource”,可以再hello.jsp页面获取/resource
  • 为action注入属性值应用于经常换的变量,这样不用更换源代码。
  • 比如该变量为使用该软件公司的名称

05. struts2中为Action属性注入值

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2022-02-20
  • 2022-12-23
  • 2021-11-04
  • 2021-08-10
  • 2021-06-05
猜你喜欢
  • 2021-12-24
  • 2022-02-12
  • 2021-10-10
  • 2021-11-01
  • 2022-12-23
  • 2021-10-10
  • 2021-05-14
相关资源
相似解决方案