天天看點

SpringMVC轉發和重定向

轉發和重定向

視圖解析器

<!--視圖解析器-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          id="internalResourceViewResolver">
        <!-- 字首 -->
        <property name="prefix" value="/WEB-INF/jsp/" />
        <!-- 字尾 -->
        <property name="suffix" value=".jsp" />
    </bean>
           

ResultSpringMVC2

package com.kuang.controller;

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

@Controller
public class ResultSpringMVC2 {
	@RequestMapping("/rsm2/t1")
	public String test1(){
		//轉發
		return "test";    //這個路徑可以從視圖解析器擷取
	}
	@RequestMapping("/rsm2/t2")
	public String test2(){
		//重定向
		**return "redirect:/index.jsp";**  //這個路徑需要是完整的路徑
	}
}
           
ssm

繼續閱讀