JSP 中的 HTTP 状态 500 并使用 JSONObject
HTTP state 500 in JSP and use JSONObject
我正在使用 Intellij IDEA 14 ULTIMATE 创建 Web 应用程序。
我想使用 html 显示和 jsp 连接 java 和 html 显示之间的数据。
所以我使用 JSONObject,在导入 json-lib-2.4-jdk15.jar
之后
使用 request/response 的方法,导入 javax.servlet.jsp-api (来自 maven)
tomcat jar 由项目自动生成。
我删除任何一个,都会出现编译错误。
i 运行 tomcat, 浏览器显示:
HTTP Status 500 - java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature
type Exception report
message java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:348)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature
org.apache.jsp.servlet.getArticle_jsp._jspInit(getArticle_jsp.java:34)
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:376)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.64 logs.
Tomcat 本地主机日志:
org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [jsp] in context with path [] threw exception [java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature] with root cause
java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature
at org.apache.jsp.servlet.getArticle_jsp._jspInit(getArticle_jsp.java:34)
at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:180)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:376)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
编辑:
jar import, module, Library, lib package, lib package in out 和 Artifacts 搞得一头雾水
确保您生成的 war 中没有这些 jars 中的一些:
Servlet-api.jar
或 javax-servlet-api.jar
或 jsp-api.jar
或 javax-servlet-jsp.jar
运行
mvn clean package
再次测试
这个问题主要是jar冲突引起的,你应该:
- 不要从maven import servlet-api和jsp-api,jar包太多,和你自己的不完全一致tomcat api.
- 从您的本地文件夹导入这两个 jar(就这些就足够了),您项目中的 tomcat 主文件夹
Moudles
->Dependencies
- import json jar pack,我推荐三个:
①json-lib(net.sf.json)
②org.json
③json-simple
2 & 3 是轻量级的,可以直接导入到 Moudles
->Dependencies
AND 复制它们到你的 web->WEB-INF->lib
如果选择第一个,则必须导入 commons-beanutils
commons-collections
commons-lang
commons-logging
ezmorph
进一步。
更好地在同一版本包中使用它们:)
我正在使用 Intellij IDEA 14 ULTIMATE 创建 Web 应用程序。
我想使用 html 显示和 jsp 连接 java 和 html 显示之间的数据。
所以我使用 JSONObject,在导入 json-lib-2.4-jdk15.jar
之后
使用 request/response 的方法,导入 javax.servlet.jsp-api (来自 maven)
tomcat jar 由项目自动生成。
我删除任何一个,都会出现编译错误。 i 运行 tomcat, 浏览器显示:
HTTP Status 500 - java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature
type Exception report
message java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature
description The server encountered an internal error that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:348)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature
org.apache.jsp.servlet.getArticle_jsp._jspInit(getArticle_jsp.java:34)
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:376)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.64 logs.
Tomcat 本地主机日志:
org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [jsp] in context with path [] threw exception [java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature] with root cause
java.lang.LinkageError: loader constraint violation: when resolving method "org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager;" the class loader (instance of org/apache/jasper/servlet/JasperLoader) of the current class, org/apache/jsp/servlet/getArticle_jsp, and the class loader (instance of org/apache/catalina/loader/StandardClassLoader) for resolved class, org/apache/jasper/runtime/InstanceManagerFactory, have different Class objects for the type he.jasper.runtime.InstanceManagerFactory.getInstanceManager(Ljavax/servlet/ServletConfig;)Lorg/apache/tomcat/InstanceManager; used in the signature
at org.apache.jsp.servlet.getArticle_jsp._jspInit(getArticle_jsp.java:34)
at org.apache.jasper.runtime.HttpJspBase.init(HttpJspBase.java:49)
at org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:180)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:376)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
编辑:
jar import, module, Library, lib package, lib package in out 和 Artifacts 搞得一头雾水
确保您生成的 war 中没有这些 jars 中的一些:
Servlet-api.jar
或 javax-servlet-api.jar
或 jsp-api.jar
或 javax-servlet-jsp.jar
运行
mvn clean package
再次测试
这个问题主要是jar冲突引起的,你应该:
- 不要从maven import servlet-api和jsp-api,jar包太多,和你自己的不完全一致tomcat api.
- 从您的本地文件夹导入这两个 jar(就这些就足够了),您项目中的 tomcat 主文件夹
Moudles
->Dependencies
- import json jar pack,我推荐三个:
①json-lib(net.sf.json)
②org.json
③json-simple
2 & 3 是轻量级的,可以直接导入到Moudles
->Dependencies
AND 复制它们到你的web->WEB-INF->lib
如果选择第一个,则必须导入commons-beanutils
commons-collections
commons-lang
commons-logging
ezmorph
进一步。 更好地在同一版本包中使用它们:)