码迷,mamicode.com
首页 > 编程语言 > 详细

SpringMVC之转发重定向

时间:2019-10-19 09:16:37      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:alt   title   import   操作   视图   htm   meta   ann   tty   

package com.tz.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ViewController {
	
	@RequestMapping("/view")
	public String view(){
		return "../../view";//相对路径
	}
	
	@RequestMapping("/view02")
	public String view02(){
		return "forward:/view.jsp";//转发,有前缀的返回值独立解析
	}
	
	@RequestMapping("/view03")
	public String view03(){//发送给view02进行处理
		return "forward:/view";
	}
	
	@RequestMapping("/view04")
	public String view04(){
		//response.sendRedirect("/项目名/view.jsp");
		return "redirect:/view.jsp";//代表当前项目下开始,springmvc会自动为路径拼接上项目名
	}
	
	@RequestMapping("/view05")
	public String view05(){//中转站
		//response.sendRedirect("/项目名/view.jsp");
		return "redirect:/view04";//代表当前项目下开始,springmvc会自动为路径拼接上项目名
	}
	
	//使用前缀的转发或者重定向操作,配置的视图解析器就不会帮助拼接字符串
}

  技术图片

 

 index.jsp页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<a href="view">view</a>
	<a href="view02">view02</a>
	
	<a href="view03">view03</a>
	
	<a href="view04">重定向</a>
</body>
</html>

  

SpringMVC之转发重定向

标签:alt   title   import   操作   视图   htm   meta   ann   tty   

原文地址:https://www.cnblogs.com/luyuan-chen/p/11702728.html

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