概述

  • 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注入属性值利用于常常换的变量,这样不必更换源代码。
  • 比方该变量为应用该软件公司的名称