SpringMVC ModelAndView 无法跳转
最编程
2024-04-29 21:41:11
...
视图解析器能解析不能跳转,能解析,return modelandview 也有返回值。但是就是不能调转。
2019-8-20更新如下:
modelandview 不能跳转有几种情况:
1、你的包别导错了。import org.springframework.web.servlet.ModelAndView;
2、springmvc-*.xml里面的视图解析器不能错:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
//前缀
<property name="prefix" value="/jsp/" />
//后缀
<property name="suffix" value=".jsp" />
</bean>
3、别用ajax提交,ajax提交时不会跳转的;
假设-ajax 提交:
除非是回调过去之后用window.location.href = contextPath + 'index';
$.post('url', data, function(res) {
if (res.status == 1) {
// 成功
window.location.href = contextPath + 'index';
} else {
// 失败
}
})