未定义方法getDispatcherType

未定义方法getDispatcherType

本文介绍了对于HttpServletRequest类型,未定义方法getDispatcherType()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从Eclipse运行我的应用程序时,它运行时没有任何servlet api 3.1.0和3.0.1的错误。

When I run my applicaiton from Eclipse it runs without any errors for servlet api 3.1.0 and 3.0.1.

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
</dependency>

我使用tomcat 8.0.21进行eclipse。我在ubuntu机器上设置了tomcat8,它运行在tomcat 8.0.14稳定版本上。

I use tomcat 8.0.21 for eclipse. I have set up tomcat8 on ubuntu machine which runs on tomcat 8.0.14 stable version.

不幸的是,如果我使用servlet api 3.1.0,我会收到以下错误消息。但它适用于旧版本3.0.1。

Unfortunately, I get the following error message if I use servlet api 3.1.0. But it works for the older version 3.0.1.

root cause

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

An error occurred at line: [50] in the generated java file: [/var/lib/tomcat8/work/Catalina/localhost/ROOT/org/apache/jsp/WEB_002dINF/view/templates/login_002dtemplate_jsp.java]
The method getDispatcherType() is undefined for the type HttpServletRequest

Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:199)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:450)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:725)

为什么会出现此错误?如何解决这个问题?

Why do I get this error? How to fix this?

推荐答案

如果目标运行时已经存在,则不应该提供Servlet API和Web应用程序存档提供API开箱即用。 Tomcat作为JSP / Servletcontainer已经开箱即用,提供了JSP,Servlet和EL API。无论如何,当您将它们与webapp一起提供时,您可能会遇到由来自webapp和服务器的运行时类路径中的重复不同版本类引起的类加载冲突。

You're not supposed to provide Servlet API along with the web application archive if the target runtime already provides the API out the box. Tomcat as being a JSP/Servletcontainer already provides JSP, Servlet and EL APIs out the box. When you provide them along with your webapp anyway, then you may run into classloading conflicts caused by duplicate different versioned classes in the runtime classpath coming from both the webapp and the server.

< scope>提供< / scope> 添加到目标运行时已提供的依赖项中。

Add <scope>provided</scope> to those dependencies already provided by the target runtime.



  • How do I import the javax.servlet API in my Eclipse project?

这篇关于对于HttpServletRequest类型,未定义方法getDispatcherType()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 23:46