struts2 的 @Result 和 @ResultPath 联合使用
来源:互联网 发布:光头成男脸型数据 编辑:程序博客网 时间:2024/06/08 08:37
对于使用了 struts2 的 convention 插件进行开发时,我们知道可以通过以下的配置项来约定所有的 Result 视图的路径:
<constant name="struts.convention.result.path" value="/WEB-INF/content/"/>
上面的value就是 convention 插件 中的默认值,当然,我们可以改成任意我们想要的值。
这样的话,当我们声明以下的@Result时:
@Result(name = "success", location = "my-upload.jsp")
系统就会试着去访问如下的文件:
/WEB-INF/content/my-upload.jsp
如果存在,那就OK,不然就会报404的错误。
对于result path,我也可以使用@ResultPath进行个别定制,如:
@Results(@Result(name = "success", location = "my-upload.jsp"))@ResultPath("/jsp")public class File2Action {public String upload() {System.out.println("uploading files...");return "success";}}
这样一来,虽然“struts.convention.result.path”的值为“/WEB-INF/content/”,但是我们这边使用了@ResultPath 注解对其进行了覆盖,所以,这边实际访问的页面为:
/jsp/my-upload.jsp
PS:以上的结果,均以“Action”的namespace为“/” 为前提,即url应该以如下这种情况的:
http://xxx.xxx.xxx.xxx:port/web工程名/file2!upload
对于action的namespace怎么设定,大家查看一下官网说明:http://struts.apache.org/docs/convention-plugin.html#ConventionPlugin-Codebehindhelloworld
不过,有一点,我们需要特别注意:
上面的
location = "my-upload.jsp"
中,“my-upload.jsp” 没有以 “/” 开头,所以,也就是说它是一个相对路径,这样,它才会基于@ResultPath中的路径去找相应的文件。
如果,我们将其修改成如下:
location = "/my-upload.jsp"
即,让“my-upload.jsp”以"/"开头,这时候,它就是一个绝对路径,这个时候,它不是会基于@ResultPath中的路径去搜索相关的文件的,而是直接基于web工程的根路径去搜索相关文件。
也就是说,假设你的web工程的名字就 test,那么此时它访问的页面为:
http://xxx.xxx.xxx.xxx:port/test/my-upload.jsp
- struts2 的 @Result 和 @ResultPath 联合使用
- struts2 的 @Result 和 @ResultPath 联合使用
- struts2 :result type的使用
- struts2中result的使用
- Struts2的cosntant和result
- struts2 全局result和动态result的用法
- struts2 Result类型和对应的用法
- 【struts2】Result和ResultType
- struts2 中dispatcher、redirect和chain三种result type的使用区别
- struts2 中dispatcher、redirect和chain三种result type的使用区别
- struts2的result标签
- Struts2 的Result Type
- Struts2的Result Type
- Struts2的Result Type
- Struts2 的 Result
- Struts2 的 Result Type
- struts2的Result类型
- Struts2的Result Type
- 五个解决方案让MongoDB拥有RDBMS的鲁棒性事务
- java上传多媒体文件
- 职业生涯管理系统 servlet+javabean+mysql(一)软件的安装与配置
- iOS日常需求:iOS开发隐藏StatusBar
- 解决vbox安装centos不能上网问题
- struts2 的 @Result 和 @ResultPath 联合使用
- setjmp和longjmp解析
- haproxy 源码安装
- MySQL分区性能初探
- 怎样创建合适的告警处理流程?
- maven 打包的时候跳过测试
- 一点点积累—spring配置
- Linux每日学习(七)
- Leetcode233: Scramble String