通过<param/>节点注入
- <action name="setValue" class="blog.action.HelloWorld" method="add">
- <param name="savePath">/path</param>
- </action>
- package blog.action;
- import java.io.UnsupportedEncodingException;
- import java.net.URLEncoder;
- public class HelloWorld {
- private String savePath;
- private String msg;
- private String uname;
- public String getUname() {
- return uname;
- }
- public void setUname(String uname) {
- this.uname = uname;
- }
- public String getMessage() {
- return msg;
- }
- public String getSavePath() {
- return savePath;
- }
- public void setSavePath(String savePath) {
- this.savePath = savePath;
- }
- public String execute(){
- try {
- uname = URLEncoder.encode("张三","UTF-8");//ISO8859-1
- } catch (UnsupportedEncodingException e) {
- e.printStackTrace();
- }
- msg = "This is my first struts2 application!!!";
- return "success";
- }
- public String add(){
- return "message";
- }
- }
- https://blog.csdn.net/xzf19901108/article/details/7771027