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>
    

      

  • 相关阅读:
    ASP.NET学习线路(转)
    创建variant二维数组
    域名”A记录,MX记录,CNAME记录,TTL值,URL转发”解释
    数据库表行转列,列转行终极方案(转)
    [转载]oracle备份与恢复精华资料
    事务的概念
    Velocity语言的介绍
    初步认识JUnit
    JSON基本用法
    matplotlib入门
  • 原文地址:https://www.cnblogs.com/luyuan-chen/p/11702728.html
Copyright © 2011-2022 走看看