当我尝试在Tomcat 7上运行webapp时,出现以下异常:
exception javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory; " the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/index_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type javax/el/ExpressionFactory used in the signature org.apache.jasper.servlet.JspServlet.service(JspServlet.java:343) javax.servlet.http.HttpServlet.service(HttpServlet.java:722) root cause java.lang.LinkageError: loader constraint violation: when resolving interface method "javax.servlet.jsp.JspApplicationContext.getExpressionFactory()Ljavax/el/ExpressionFactory;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/index_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, javax/servlet/jsp/JspApplicationContext, have different Class objects for the type javax/el/ExpressionFactory used in the signature org.apache.jsp.index_jsp._jspInit(index_jsp.java:31) org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49) org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:180) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
似乎两个.jar库之间存在冲突,但我不知道它们是哪个。我该如何解决它们?
.jar
当你包括在不同的服务器品牌/版服务器专用库,会发生/WEB-INF/lib你的web应用,如jsp-api.jar,el- api.jar,servlet-api.jar,等你需要 删除 它们。该/WEB- INF/lib不应包含任何服务器专用库。它们属于特定的服务器本身(Tomcat已将其放在其/lib文件夹中)。
/WEB-INF/lib
jsp-api.jar
el- api.jar
servlet-api.jar
/WEB- INF/lib
/lib
顺便说一句,这是每当初学者在IDE项目中的JSP / Servlet API上遇到编译错误时,都会犯的错误。应该以不同的方式解决此问题,即通过将服务器集成到IDE中并将服务器作为“目标运行时”添加到项目中。