Java getDispatcherType() 对于 HttpServletRequest 类型未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26436463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
getDispatcherType() is undefined for the type HttpServletRequest
提问by no_lyf_programmer
I have imported a Java dynamic web project into the Eclipse IDE (which was implemented in Eclipse IDE and properly working).
我已将 Java 动态 Web 项目导入 Eclipse IDE(在 Eclipse IDE 中实现并正常工作)。
I'm getting a "getDispatcherType()
is undefined for the type HttpServletRequest
" error while running the project.
我在运行项目时收到“getDispatcherType()
未定义类型HttpServletRequest
”错误。
I have copied every file into IDE as per the structure and the work is done.
我已按照结构将每个文件复制到 IDE 中,并且工作已完成。
Now I just want to know why I am getting this error when I have imported the project. Did anyone faced the same issue? Please let me know what mistake I might have made.
现在我只想知道为什么在导入项目时会出现此错误。有没有人遇到过同样的问题?请让我知道我可能犯了什么错误。
采纳答案by James Boutcher
I had the same issue when I had a conflicting servlet-api version I was using in IntelliJ that conflicted with what was supported in Tomcat 8.0.x... I was using Maven, so I just changed my dependency to this, then did a clean deploy of my webapp and the problem went away.
当我在 IntelliJ 中使用的 servlet-api 版本与 Tomcat 8.0.x 支持的版本冲突时,我遇到了同样的问题......我使用的是 Maven,所以我只是将我的依赖项更改为这个,然后做了一个干净部署我的 web 应用程序,问题就消失了。
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
回答by zond
tomcat 8.0.18, maven. It's about lib conflict. My solution is:
Tomcat 8.0.18,Maven。这是关于lib冲突的。我的解决办法是:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
changed to:
变成:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
回答by Jef
This can also happen when upgrading from an old to newer Tomcat version and keeping the old jar files such as j2ee.jar and javaee.jar.
当从旧的 Tomcat 版本升级到新的 Tomcat 版本并保留旧的 jar 文件(例如 j2ee.jar 和 javaee.jar)时,也会发生这种情况。
j2ee.jar should nerver be include in your webapp, the interfae is implemented by tomcat
j2ee.jar 应该包含在你的 webapp 中,接口是由 tomcat 实现的
回答by Tony Vu
I solved this problem by using the servlet-api.jar and jsp-api.jar from tomcat itself, so the dependency will be specified with system scope like below:
我通过使用 tomcat 本身的 servlet-api.jar 和 jsp-api.jar 解决了这个问题,因此依赖项将使用系统范围指定,如下所示:
<servlet.api.jar.path>/opt/apache-tomcat-8.0.15/lib/servlet-api.jar</servlet.api.jar.path>
<jsp.api.jar.path>/opt/apache-tomcat-8.0.15/lib/jsp-api.jar</jsp.api.jar.path>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${servlet.api.jar.path}</systemPath>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.2</version>
<scope>system</scope>
<systemPath>${jsp.api.jar.path}</systemPath>
</dependency>
回答by Juan Carrey
You should exclude "servlet-api-2.5.jar"from any other dependency that you may have in your pom.xml.
您应该从 pom.xml 中可能具有的任何其他依赖项中排除“servlet-api-2.5.jar”。
Try not to add a different servlet-api as compile, as your tomcat already provides it for you.
尽量不要添加不同的 servlet-api 作为编译,因为你的 tomcat 已经为你提供了它。
My steps:
我的步骤:
I have checked that there was a servlet-api-2.5.jar being included in my WEB-INF/lib folder by Maven, so then, I checked the full dependency graph on "Maven projects @IntelliJ Idea", then I excluded this dependency from ALL the places where it comes from. [ The button "Show dependencies" comes handy for this ]
我已经检查过 Maven 包含在我的 WEB-INF/lib 文件夹中的 servlet-api-2.5.jar,然后,我检查了“Maven 项目 @IntelliJ Idea”的完整依赖关系图,然后我排除了这个依赖关系来自它来自的所有地方。[“显示依赖项”按钮对此很方便]
I had to exclude "commons-logging" (as it has servlet-api 2.5 dependency) from velocity-tools. Also had to exclude servlet-api from jaxws-spring which has a direct dependency on default scope.
我不得不从velocity-tools 中排除“commons-logging”(因为它具有servlet-api 2.5 依赖项)。还必须从 jaxws-spring 中排除 servlet-api,它直接依赖于默认范围。
Then, just add the scope provided as you should on your javax.servlet-api dependency.
然后,只需在 javax.servlet-api 依赖项上添加您应该提供的范围。
If you add your servlet-api 3.0.1+ as "compile", you may end up with both, and the first to load will win, which is not good at all.
如果将servlet-api 3.0.1+ 添加为“编译”,则可能最终两者兼而有之,第一个加载的将获胜,这一点都不好。
Note:My guess is that this problem comes from the renaming of the groupId/artifactId of servlet-api, and not being overriden with the oldest version included on maven project. :\
注意:我的猜测是这个问题来自于 servlet-api 的 groupId/artifactId 的重命名,并且没有被 maven 项目中包含的最旧版本覆盖。:\
回答by Gerbert Santos
If your tomcat is version 8 use:
如果您的 tomcat 是版本 8,请使用:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
worked!
工作!