码迷,mamicode.com
首页 > 其他好文 > 详细

Struts2的@ResultPath

时间:2014-08-16 19:40:00      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   strong   ar   

转自:http://blog.csdn.net/yandufeng/article/details/8105495

 

这里我要补充一下:要理解Annotation,最好的方法还是看源码,struts中convention的源码在struts2-convention-plugin-2.1.6.jar 中

 

在struts2中,@ResultPath annotation是用来控制struts2在哪里找储存的jsp页面,默认它找jsp页面在WEB-INF/content/目录中

@ResultPath example

一个action类,设置/user为namespace,跳转到/pages/login.jsp页面

 

1 @Namespace("/User")
2 @Result(name="success",location="pages/login.jsp")
3 public class LoginAction extends ActionSupport{
4 }

 

访问它

http://localhost:8080/Struts2Example/User/login.action

 

Struts 2将会发现 the “login.jsp” 从默认的位置

/Struts2Example/WEB-INF/content/User/pages/login.jsp

 

自定义ResultPath

1 @Namespace("/User")
2 @ResultPath(value="/")
3 @Result(name="success",location="pages/login.jsp")
4 public class LoginAction extends ActionSupport{
5 }

http://localhost:8080/Struts2Example/User/login.action
/Struts2Example/pages/login.jsp

 

全局的@ResultPath

 

@ResultPath仅仅适用于类级别,为了让它全局化,你可以配置它在struts.xml中

struts.xml

 

1 <?xml version="1.0" encoding="UTF-8" ?>
2 <!DOCTYPE struts PUBLIC
3 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
4 "http://struts.apache.org/dtds/struts-2.0.dtd">
5 <struts>
6     <constant name="struts.convention.result.path" value="/"/>
7 </struts>

 

Struts2的@ResultPath,布布扣,bubuko.com

Struts2的@ResultPath

标签:style   blog   http   color   os   io   strong   ar   

原文地址:http://www.cnblogs.com/x_wukong/p/3916763.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!