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";//轉(zhuǎn)發(fā),有前綴的返回值獨(dú)立解析
}
@RequestMapping("/view03")
public String view03(){//發(fā)送給view02進(jìn)行處理
return "forward:/view";
}
@RequestMapping("/view04")
public String view04(){
//response.sendRedirect("/項(xiàng)目名/view.jsp");
return "redirect:/view.jsp";//代表當(dāng)前項(xiàng)目下開始,springmvc會(huì)自動(dòng)為路徑拼接上項(xiàng)目名
}
@RequestMapping("/view05")
public String view05(){//中轉(zhuǎn)站
//response.sendRedirect("/項(xiàng)目名/view.jsp");
return "redirect:/view04";//代表當(dāng)前項(xiàng)目下開始,springmvc會(huì)自動(dòng)為路徑拼接上項(xiàng)目名
}
//使用前綴的轉(zhuǎn)發(fā)或者重定向操作,配置的視圖解析器就不會(huì)幫助拼接字符串
}

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>
浙公網(wǎng)安備 33010602011771號