美文网首页
05. struts2中为Action属性注入值

05. struts2中为Action属性注入值

作者: c9096743e3b0 | 来源:发表于2020-11-26 01:29 被阅读0次

概述

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

相关文章

网友评论

      本文标题:05. struts2中为Action属性注入值

      本文链接:https://www.haomeiwen.com/subject/zjaoiktx.html