步遥情感网
您的当前位置:首页问题“The method getDispatcherType() is undefined for the type HttpServletRequest”

问题“The method getDispatcherType() is undefined for the type HttpServletRequest”

来源:步遥情感网

原来正常运行的项目,加了些功能后,突然遇到了 个错误:

严重: Servlet.service() for servlet [jsp] in context with path [/smsm1] threw exception [Unable to compile class for JSP: 


An error occurred at line: [65] in the generated java file: [D:\Tomcat8\work\Catalina\localhost\smsm1\org\apache\jsp\pages\bookList_jsp.java]
The method getDispatcherType() is undefined for the type HttpServletRequest


Stacktrace:] with root cause

org.apache.jasper.JasperException: Unable to compile class for JSP:


按照错误信息中的提示The method getDispatcherType() is undefined for the type HttpServletRequest去网上查找,说是servlet-api的问题。因为项目里用的servlet-api和tomcat8下面的冲突了。

原来项目里用的是这个版本的:

pom.xml:

....

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
</dependency>

....

注释掉这句后,直接通过项目的build path引入了Tomcat8的lib下面的servlet-api.jar,项目确实正常了。

真是让人莫名其妙啊!之前也一直用的是Tomcat8,这个项目也是正常运行的。不知道哪里触动了这个异常的开关? 

查找了maven库http://mvnrepository.com,输入servlet-api后才知道,原来这个jar包早就过时了,上面有提示:


菜鸟真是伤不起啊!

最终解决办法:

将pom.xml 中原来的依赖改为:

<span style="font-size:14px;"><dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
</dependency></span>

去除build path中对servlet-api.jar的引入,项目发布后正常运行。

但是为什么会突然引发这个错误,依然是百思不得其解。

因篇幅问题不能全部显示,请点此查看更多更全内容