猿问

错误:未加载Servlet Jar…令人反感的类:javax / servlet

我收到以下错误:


INFO:validateJarFile(C:\ dev \ server \ tomcat6 \ webapps Sempedia \ WEB-INF \ lib \ servlet-api.jar)-未加载jar。参见Servlet Spec 2.3,第9.7.2节。令人反感的类:javax / servlet / Servlet.class


那里的现有资源说,这是由于与servlet.jar冲突,在本例中为servlet-api.jar文件。我已经从/ webapps文件夹中删除了所有其他项目,我已经获取了tomcat6 / lib目录中的servlet-api.jar文件,并将其添加到了项目构建路径中,所以我看不到那里仍然是一个冲突。


当我尝试运行该应用程序时,得到以下堆栈跟踪。


org.apache.jasper.JasperException:无法为JSP编译类:


在生成的java文件中的第22行发生错误:对于类型JspFactory,未定义方法getJspApplicationContext(ServletContext)。


堆栈跟踪:


org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler。 java:439)org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)org.apache.jasper.compiler.Compiler。 compile(Compiler.java:299)org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)org.apache.jasper.servlet。 JspServlet.serviceJspFile(JspServlet.java:342)org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)javax.servlet.http.HttpServlet.service(HttpServlet.java:717)


冉冉说
浏览 657回答 3
3回答

HUH函数

就像其他答案所说的那样,这是因为您的WAR包含Servlet API类,但不应这样做。如果使用Maven构建项目,则需要告诉Maven在编译和测试时使Servlet API可用,但不要将其包含在WAR中。正如有关依赖范围的Maven文档所述,您应该provided对Servlet API 使用范围:&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>javax.servlet</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>servlet-api</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>2.5</version>&nbsp; &nbsp; &nbsp; &nbsp; <scope>provided</scope>&nbsp; &nbsp; </dependency>如果您的某些依赖关系将Servlet API作为编译依赖关系引入,则可能还必须显式排除Servlet API作为传递依赖关系:&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.example</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>frob-driver-core</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.0.1</version>&nbsp; &nbsp; &nbsp; &nbsp; <exclusions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>servlet-api</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>javax.servlet</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusion>&nbsp; &nbsp; &nbsp; &nbsp; </exclusions>&nbsp; &nbsp; </dependency>
随时随地看视频慕课网APP

相关分类

Java
我要回答