”forward:”或者”redirect:”开头
,则会被认为是转发或者重定向。使用方式如下:
注意:后面必须跟上URL路径而非视图名
转发地址栏不变
重定向地址栏变化
变化后
TestController11.java
package com.deng.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
//jstl的用法
@Controller
public class TestController11 {
//转发
@RequestMapping("show28")
public String test28(){
return "forward:/show29.do?type=forward";
}
@RequestMapping("show29")
public String test29(Model model,@RequestParam("type") String type){
model.addAttribute("msg11", "转发或重定向:type=" + type);
return "forword_redirect";
}
//重定向
/**
* 重定向到/show29.do
* @return
*/
@RequestMapping("show30")
public String test30(){
return "redirect:/show29.do?type=redirect";
}
}
forword_redirect.jsp
<%--
Created by IntelliJ IDEA.
User: U100926
Date: 2022/09/02
Time: 14:51
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<span style="font-size:30px; color:darkgreen;">${msg11}</span>
</body>
</html>