struts2为Action的属性注入值

通过<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";
    }

}



posted @ 2012-07-21 19:15  xzf007  阅读(181)  评论(0编辑  收藏  举报