struts2Action的属性注入值

类:

package control.center;

import java.net.URLEncoder;

public class HelloWordAction {

 private String savePath;
 
 public String getSavePath() {
  return savePath;
 }
 public void setSavePath(String savePath) {
  this.savePath = savePath;
 }
 public String execute() throws Exception{
  URLEncoder.encode("星期三","UTF-8");
  return "hello word!";
 }
 
}

Action配置:

<action name="hello" class="control.center.HelloWordAction" method="execute">
             <param name="savepath">/images</param>
             <param name="success">/WEB-INF/page/message.jsp</param>

</action>

将路径注入到类的savepath属性中。

在页面上使用:

${savePath}得到savePath的值

访问Action的默认后缀是.action,可以通过struts.action.extenstion修改默认后缀

,在struts配置中使用配置节点:<constant name="struts.action.extension" value="do"/>

此配置将.action修改为.do

原文地址:https://www.cnblogs.com/jinzhengquan/p/1963208.html