struts2 一些注解

实现的JSP页面位置 web-root/jsp/user/add.jsp

                                   /update.jsp

//

/*

@Namespace("/t")

@AllowedMethods(value={"add","update"}) //方法,如test!add

@Action(value="test",

results=

{@Result(name="add",location="/WEB-INF/jsp/user/add.jsp"),

 @Result(name="update",location="/WEB-INF/jsp/user/update.jsp")}

                   )

*/

//这个例子,将/t改为/user。ResultPath的默认是/WEB-INF/content/ (struts2的默认)

//但是,如果用了ResultPath,则覆盖。访问地址是 <工程路径>/@ResultPath/<@Namespace>/ @Result.location

//如user没有改t,则, <工程路径>//WEB-INF/jsp/t/update.jsp

//若转发(dispatcher)需要用这种用法,可jsp文件放置与namespace相同名称的文件夹中。

//若是重定向type="redirect",同样会有/t, 即<工程路径>/t/index.jsp  (location="index.jsp")

//location="/",返回工程路径。

@Namespace("/user") 

@AllowedMethods(value={"add","update","execute"}) //方法,如test!add

@ResultPath("/WEB-INF/jsp/")

@Action(value="test",

results=

{@Result(name="add",location="add.jsp"),

 @Result(name="update",location="update.jsp",type="dispatcher"),

@Result(name="success",location="index.jsp",type="redirect")}

                   )

public class TestAction extends ActionSupport{

        

         private Date date;

         public String add(){

                   date=new Date();

                   return "add";

                  

         }

        

         public String update(){

                   date=new Date();

                   return "update";

                  

         }

         public Date getDate() {

                   return date;

         }

         public void setDate(Date date) {

                   this.date = date;

         }

}

原文地址:https://www.cnblogs.com/jway1101/p/5833907.html