The forward and redirect SpringMVC

com.tz.controller Package; 

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

@Controller 
public class the ViewController { 
	
	@RequestMapping ( "/ View") 
	public String View () { 
		return "../../view";// relative path 
	} 
	
	@RequestMapping (" / view02 ") 
	public String view02 () { 
		return" forward: /view.jsp "; // forwarding prefix return value independent parse 
	} 
	
	@RequestMapping ( "/ view03") 
	public String view03 () {// view02 sent for processing to 
		return "Forward: / View"; 
	} 
	
	@RequestMapping ( "/ view04") 
	public String view04 () { 
		//response.sendRedirect ( "/ project name / view.jsp"); 
		return "the redirect: / view.jsp ";// represents the current project at the beginning, springmvc will automatically stitching on the path project name 
	}
	 
	@ RequestMapping ( "/ view05") 
	public String view05 () {// transfer station 
		//response.sendRedirect ( "/ item name /view.jsp"); 
		return "the redirect: / view04"; // start representatives, SpringMVC automatically spliced to the path name of the current project 
	} 
	
	// prefix using the forward or redirect operation, configuration the view resolvers will not help string concatenation 
}

  

 

 index.jsp page

<%@ 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>

  

Guess you like

Origin www.cnblogs.com/luyuan-chen/p/11702728.html