zoukankan      html  css  js  c++  java
  • SpringMVC之转发重定向

    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>
    

      

  • 相关阅读:
    shell语句for循环
    ls命令详解
    计算机相关概念总结(3)
    计算机相关概念总结(2)
    计算机相关概念总结(1)
    devops的概念
    jenkins无法连接gitlab
    Jenkins创建镜像后无法推送到harbor的问题
    Jenkins+gitlab+maven持续集成
    jenkins打完包在哪里
  • 原文地址:https://www.cnblogs.com/luyuan-chen/p/11702728.html
Copyright © 2011-2022 走看看