/**
* 跳转到登录页
* http://localhost:8080/web-0.0.1-SNAPSHOT/index/index
*
* @return
*/
@ResponseBody
@RequestMapping(value = "/index", method = { RequestMethod.GET })
public ModelAndView index(HttpSession httpSession) {
ModelAndView mav = new ModelAndView();
if(checkUser(httpSession)) {
mav.setViewName("statis/index");
}else {
mav.setViewName("index/index");//使用简写进行jsp页面跳转,需要在applicationContext-mvc.xml文件中配置跳转到jsp视图的前后缀
}
return mav;
}
Controller层跳转jsp视图,如果使用简写方式跳转,则需要在spring的xml中配置jsp的前后缀。
applicationContext-mvc.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans ...>
<!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 静态资源文件,不会被Spring MVC拦截 -->
<mvc:resources location="/" mapping="/**/*.html"/>
<mvc:resources location="/" mapping="/**/*.js"/>
<mvc:resources location="/" mapping="/**/*.css"/>
<mvc:resources location="/" mapping="/**/*.png"/>
<mvc:resources location="/" mapping="/**/*.jpg"/>
<mvc:resources location="/" mapping="/**/*.gif"/>
</beans>