Spring MVC 中的 forward 和 redirect
来源:互联网 发布:云控软件 编辑:程序博客网 时间:2024/04/28 19:58
Spring MVC 中的 forward 和 redirect
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <description> 假如逻辑试图名为 "hello",因此 viewResolver 将解析成 /WEB-INF/jsp/hello.jsp </description> <property name="order" value="10" /> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean>实际上,框架还是通过 forward 的方式转发到了 /WEB-INF/jsp/hello.jsp。如果逻辑视图名是 /hello,实际还是转发到了 /WEB-INF/jsp/hello.jsp,即 /WEB-INF/jsp//hello.jsp 等同于 /WEB-INF/jsp/hello.jsp。
现在有个问题,如果 /hello 就是某个 controller 的映射,我想转发到这个 controller,怎么办?我们可以通过forward 前缀来达到转发到其它资源的目的:
public String handle() { // return "forward:/hello" => 转发到能够匹配 /hello 的 controller 上 // return "hello" => 实际上还是转发,只不过是框架会找到该逻辑视图名对应的 View 并渲染 // return "/hello" => 同 return "hello" return "forward:/hello"; }
同理,如果我们想重定向到某个资源,我们可以通过 redirect 前缀来达到重定向到其它资源的目的:
public String handle() { // 重定向到 /hello 资源 return "redirect:/hello"; }
0 0
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Spring MVC 中的 forward 和 redirect
- Sql server force select,delete with index
- atoi 的 C 语言实现
- jquery图表工具
- 7-1通信系统中为什么要进行编码和解码?常见的编码方法有哪些?
- python模块:xlsxwriter和xlrd相结合读取、写入excel文件
- Spring MVC 中的 forward 和 redirect
- HIVE1.1.0报错记录
- ipsec---icmp: ipsec中icmp的处理
- hdu 5204 Rikka with sequence && BestCoder Round #37
- LeetCode(055) Jump Game (Java)
- 在Java中利用Jackson解析JSON数据
- 03-SQLite3之insert、select、where
- 如何更优雅的书写Javascript之告别回调地狱
- Linux命令之ifconfig - 网络配置命令