Struts2 二、为Action的参数注入值

来源:互联网 发布:利用淘宝运费险赚钱 编辑:程序博客网 时间:2024/04/29 21:12

为Action参数注入值,主要使用在的场景为,Action的一个参数的值不是固定的是可以改变的,所以不能直接写在Action中,可以通过Struts配置的方式将值配置到Struts中,然后通过注入的方式将值注入到Action中,下面是代码:

public class HelloAction {public String resultParam;public String sayHello(){return "message";}public String getResultParam() {return resultParam;}public void setResultParam(String resultParam) {this.resultParam = resultParam;}}


struts-config代码:

<package name="hello" namespace="/hello" extends="struts-default"><action name="helloAction_*" class="cn.actions.HelloAction" method="{1}"> <param name="resultParam">我的名字是:</param><result name="message">/WEB-INF/pages/message.jsp</result></action></package>

message.jsp代码:

<body>   ${resultParam} 杰克   </body>

访问地址:http://localhost:9000/Struts2/hello/helloAction_sayHello.do

0 0