坑1: tomcat-embed-jasper包依赖
SpringMVC中jsp请求流程:
servlet容器收到请求,分发到SpringMVC的DispatcherServlet.
SpringMVC经过处理,返回jsp视图名称,随后通过InternalResourceViewResolver解析得到InternalResourceView
InternalResourceView通过forward方式服务器内部跳转
servlet容器再次收到请求,由于本次请求中url中带有.jsp后缀,所以分发给JspServlet处理
JspServlet在第一次被调用时使用jsp引擎解析jsp文件,并生成servlet,并注册
现象:
当InternalResourceView进行forward之后,请求又进入到了SpringMVC的DispatcherServlet中
原因:
JspServlet没有被注册到Servlet容器中,所以请求分发到DispatcherServlet来处理
解决方案就是添加依赖:
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>compile</scope>