java.lang.NoClassDefFoundError:javax / servlet / http / HttpServletRequest [英] java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest

查看:237
本文介绍了java.lang.NoClassDefFoundError:javax / servlet / http / HttpServletRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个servlet,它收到一个包含多个文件的多部分请求,并且我使用的是apache commons文件上传库。



当我调用 parseRequest(request); 方法servlet抛出以下异常:

  GRAVE:Servlet .service()for servlet DiffOntology抛出异常
java.lang.NoClassDefFoundError:java.sql.servletRequest
在)
在org.apache.commons.fileupload.FileUploadBase $ FileItemIteratorImpl。< init>(FileUploadBase.java:882)
在org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java: 331)
在org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:349)
在org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
在DiffOntology.doPost(DiffO ntology.java:38)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
在javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在org .tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
在org.apache .catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
在org.apache.catalina.core .StandardContextValve.invoke(StandardContextValve.java:191)
在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
在org.apache.catalina。 valve.ErrorReportValve.invoke(ErrorReportValve.java:102)
在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
在org.apache.catalina.connector.CoyoteAdapter。 service(CoyoteAdapter.java:298)
在org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
在org.apache.coyote.http11.Http11Protocol $ Http11ConnectionHandler.process( Http11Protocol.java:588)
在org.apache.tomcat.util.net.JIoEndpoint $ Worker.run(JIoEndpoint.java:489)
在java.lang.Thread.run(Thread.java: 619)

我将所有库放在WEB-INF / lib中。



编辑:



servlet-api.jar在正确的目录(tomcat / lib)中,所有其他库都在WEB-INF / lib



我想也许这个问题可能如下:
我正在Eclipse中开发这个Web项目,我在类路径中导入了文件上传库。 / p>

如何不起作用? p>

我绝望!!

解决方案

在webapp的 / WEB-INF / lib 或可能 JRE / lib 中放置服务器特定的库。很可能你将Tomcat的 /lib/servlet-api.jar 复制到那里。你不应该这样做这只会导致类路径中的冲突,这会导致这种错误,并且会使您的webapp不可移植(即它绑定到仅在Tomcat上运行,您不能在另一台服务器上运行,如Glassfish,JBoss AS,Websphere ,等等)。您应该将服务器特定的库保持在默认位置。从任何特定于服务器的库中清理 / WEB-INF / lib 并从任何第三方库清理 JRE / lib



由于您无法编译您的servlet,因此您可能会复制特定于服务器的库。在 / WEB-INF / lib 中复制库是错误的解决方案。您应该基本上只是在compiletime类路径中指定这些库。由于您使用的是Eclipse,因此可以轻松完成此操作:首先,在服务器视图中添加Tomcat,然后将您的webapp项目与集成的Tomcat实例相关联。这样Eclipse将自动将服务器特定的库添加到项目的构建路径。在一个全新的Web项目中,您可以在项目创建向导中选择服务器。在现有的Web项目中,您可以在项目属性中的



I'm developing a servlet that receives a multipart request with content of multiple files, and I'm using apache commons file upload libraries.

When I call parseRequest(request); method servlet throws following exception:

GRAVE: Servlet.service() for servlet DiffOntology threw exception
java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
    at org.apache.commons.fileupload.servlet.ServletRequestContext.getContentType(ServletRequestContext.java:73)
    at org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.<init>(FileUploadBase.java:882)
    at org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:331)
    at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:349)
    at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
    at DiffOntology.doPost(DiffOntology.java:38)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)

I put all libraries in WEB-INF/lib.

EDIT:

servlet-api.jar is in the correct directory (tomcat/lib) and all others libraries are in WEB-INF/lib

I think maybe the problem could be the following: I'm developing this web project in Eclipse, and I imported file uploads libraries in the classpath.

How it doesn't work?

I'm desperate!!

解决方案

This can happen when you've placed server-specific libraries in the webapp's /WEB-INF/lib or probably JRE/lib. Big chance that you copied Tomcat's /lib/servlet-api.jar into there. You shouldn't do that. This would only lead to collisions in the classpath which leads to this kind of errors and it will make your webapp unportable (i.e. it is tied to run on Tomcat only, you can't run it at another servers like Glassfish, JBoss AS, Websphere, etc). You should keep the server-specific libraries at their default location. Cleanup the /WEB-INF/lib from any server-specific libraries and cleanup JRE/lib from any 3rd party libraries.

You probably copied server-specific libraries there because you wasn't able to compile your servlets. Copying the libraries in /WEB-INF/lib is the wrong solution. You should basically just specify those libraries in the compiletime classpath. Since you're using Eclipse, this can be done easily: first add Tomcat in Servers view, then associate your webapp project with the integrated Tomcat instance. This way Eclipse will automatically add the server-specific libraries to the project's buildpath. On a brand new web project you can choose the server during project creation wizard. On existing web projects, you can modify it in Targeted Runtimes section in project's properties.

See also:

这篇关于java.lang.NoClassDefFoundError:javax / servlet / http / HttpServletRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆