使用maven创建web工程,服务器选择了Tomcat 8,而servlet的版本采用的是2.5.
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency>
启动Tomcat 8,转发到jsp时出现异常信息:
getDispatcherType() is undefined for the type HttpServletRequest
这个是由于Tomcat 8支持的servlet版本与maven指定的servelet版本有冲突导致的。
可以采用如下的方法解决该error。
将
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency>
改成
<dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency>
即可。