重定向与转发

重定向与转发_第1张图片

重定向与转发_第2张图片 

 重定向与转发_第3张图片

 转发

package com.qf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
public class ModelAndViewTest1 {
     @RequestMapping("/m1/t1")
    public String test(Model model){
        model.addAttribute("msg","ModelAndViewTest1");
         return "/WEB-INF/jsp/test.jsp";
     }

}

重定向与转发_第4张图片

 重定向

package com.qf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
public class ModelAndViewTest1 {
     @RequestMapping("/m1/t1")
    public String test(Model model){
        model.addAttribute("msg","ModelAndViewTest1");
         return "redirect:/index.jsp";
     }

}

重定向与转发_第5张图片

重定向与转发_第6张图片 这是视图解析器的转发

package com.qf.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@Controller
public class ModelAndViewTest1 {
     @RequestMapping("/m1/t1")
    public String test(Model model){
        model.addAttribute("msg","ModelAndViewTest1");
         return "test";
     }

}

 重定向与转发_第7张图片

 

你可能感兴趣的:(SpringMVC,服务器,运维)