简体   繁体   English

升级到 jetty-9.3.3 后 JSP 编译错误

[英]JSP compilation error after upgrade to jetty-9.3.3

I have a webapp application which was running on embedded Jetty-7.6.8 (jdk-6), but due to Diffie-Hellman error on the browser we decided to move to newer version of Jetty.我有一个在嵌入式 Jetty-7.6.8 (jdk-6) 上运行的 webapp 应用程序,但由于浏览器上的 Diffie-Hellman 错误,我们决定迁移到更新版本的 Jetty。 So, we moved to Jetty-9.3.3.所以,我们搬到了 Jetty-9.3.3。 As Jetty-9.x needs jdk-8, I upgraded jdk also.由于 Jetty-9.x 需要 jdk-8,我也升级了 jdk。 Right now jetty is starting up with no error but when I try to access my login page I get an unable compile jsp error.现在码头启动没有错误,但是当我尝试访问我的登录页面时,我得到一个无法编译的jsp错误。

These are the dependencies:这些是依赖项:

-org.eclipse.jetty.apache-jsp-9.3.3.v20150827.jar
-org.mortbay.jasper.apache-el-8.0.23.M1.jar 
-org.mortbay.jasper.apache-jsp-8.0.23.M1.jar
-org.eclipse.jetty.orbit.org.eclipse.jdt.core-3.8.2.v20130121.jar
-jetty-continuation-9.3.3.v20150827.jar 
-jetty-http-9.3.3.v20150827.jar
-jetty-io-9.3.3.v20150827.jar 
-jetty-security-9.3.3.v20150827.jar
-jetty-server-9.3.3.v20150827.jar 
-jetty-servlet-9.3.3.v20150827.jar
-jetty-util-9.3.3.v20150827.jar 
-jetty-webapp-9.3.3.v20150827.jar
-jetty-xml-9.3.3.v20150827.jar
-servlet-api-3.1.jar

The error which comes on the log/browser:日志/浏览器上出现的错误:

HTTP ERROR 500

Problem accessing /xdadm/test.jsp. Reason:

Server Error

Caused by:

org.apache.jasper.JasperException: Unable to compile class for JSP
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:600)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:363)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:816)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1686)
at com.xcom.filter.RequestHandler.doFilter(RequestHandler.java:91)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1156)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1088)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119)
at org.eclipse.jetty.server.Server.handle(Server.java:517)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:306)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:245)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.ssl.SslConnection.onFillable(SslConnection.java:192)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:245)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)
at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213)
at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)
at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.NullPointerException
at org.apache.jasper.compiler.Validator$ValidateVisitor.<init>(Validator.java:515)
at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1853)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:217)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
... 33 more

Please, any clue or suggestion on what's going wrong.拜托,关于出了什么问题的任何线索或建议。 TIA TIA

The problem was solved after I added all these dependencies:添加所有这些依赖项后,问题得到解决:

 jetty-lib/apache-jsp/org.eclipse.jetty.apache-jsp-9.3.8.v20160314.jar
 jetty-lib/apache-jsp/org.mortbay.jasper.apache-jsp-8.0.27.jar
 jetty-lib/apache-jsp/org.eclipse.jdt.core.compiler.ecj-4.4.2.jar
 jetty-lib/apache-jsp/org.mortbay.jasper.apache-el-8.0.27.jar
 jetty-lib/jetty-annotations-9.3.8.v20160314.jar jetty-lib/jetty-continuation-9.3.8.v20160314.jar
 jetty-lib/jetty-http-9.3.8.v20160314.jar jetty-lib/jetty-io-9.3.8.v20160314.jar
 jetty-lib/jetty-plus-9.3.8.v20160314.jar jetty-lib/jetty-security-9.3.8.v20160314.jar
 jetty-lib/jetty-server-9.3.8.v20160314.jar jetty-lib/jetty-servlet-9.3.8.v20160314.jar
 jetty-lib/jetty-util-9.3.8.v20160314.jar jetty-lib/jetty-webapp-9.3.8.v20160314.jar
 jetty-lib/jetty-xml-9.3.8.v20160314.jar  jetty-lib/servlet-api-3.1.jar
 jetty-lib/setuid/jetty-setuid-java-1.0.3.jar

This how it looks like:这是它的样子:

jetty-lib/
├── apache-jsp
│   |── org.eclipse.jdt.core.compiler.ecj-4.4.2.jar
│   ├── org.eclipse.jetty.apache-jsp-9.3.8.v20160314.jar
│   ├── org.mortbay.jasper.apache-el-8.0.27.jar
│   └── org.mortbay.jasper.apache-jsp-8.0.27.jar
├── jetty-annotations-9.3.8.v20160314.jar
├── jetty-continuation-9.3.8.v20160314.jar
├── jetty-http-9.3.8.v20160314.jar
├── jetty-io-9.3.8.v20160314.jar
├── jetty-plus-9.3.8.v20160314.jar
├── jetty-security-9.3.8.v20160314.jar
├── jetty-server-9.3.8.v20160314.jar
├── jetty-servlet-9.3.8.v20160314.jar
├── jetty-util-9.3.8.v20160314.jar
├── jetty-webapp-9.3.8.v20160314.jar
├── jetty-xml-9.3.8.v20160314.jar
├── servlet-api-3.1.jar
└── setuid
    ├── 32libsetuid-linux.so
    ├── jetty-setuid-java-1.0.3.jar
    └── libsetuid-linux.so

PS: I've moved to 9.3.8 from 9.3.3 PS:我已经从 9.3.3 移到了 9.3.8

I had the same problem with Embedded Jetty Server 9.4.15 and JSP support. Embedded Jetty Server 9.4.15 和 JSP 支持也有同样的问题。 The solution is pretty simple : https://www.eclipse.org/jetty/documentation/current/embedded-examples.html#embedded-webapp-jsp解决方案非常简单: https ://www.eclipse.org/jetty/documentation/current/embedded-examples.html#embedded-webapp-jsp

You have to enable AnnotationConfiguration :您必须启用 AnnotationConfiguration :

// This webapp will use jsps and jstl. We need to enable the
// AnnotationConfiguration in order to correctly
// set up the jsp container
Configuration.ClassList classlist = Configuration.ClassList
            .setServerDefault( server );
classlist.addBefore(
            "org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
            "org.eclipse.jetty.annotations.AnnotationConfiguration" );

I have been stuck with the same error for sometime.一段时间以来,我一直遇到同样的错误。 So for anyone who comes across the same error, the answer is exactly what others pointed out - dependency management.因此,对于遇到相同错误的任何人来说,答案正是其他人指出的——依赖管理。

If you see the Caused by: java.lang.NullPointerException at org.apache.jasper.compiler.Validator$ValidateVisitor.<init>(Validator.java:515) it is caused by failure to detect/load taglibs by Apache Jasper engine.如果您Caused by: java.lang.NullPointerException at org.apache.jasper.compiler.Validator$ValidateVisitor.<init>(Validator.java:515)则它是由 Apache Jasper 引擎未能检测/加载标签库引起的。

In other words you're missing the taglibs dependency or its API or its implementation somewhere.换句话说,您在某处缺少 taglibs 依赖项或其 API 或其实现。

Make sure all the following dependencies/JARs are in your POM确保以下所有依赖项/JAR 都在您的 POM 中

 <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-jsp</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>org.mortbay.jasper</groupId> <artifactId>apache-el</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>org.mortbay.jasper</groupId> <artifactId>apache-jsp</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>org.mortbay.jasper</groupId> <artifactId>jasper-jsp</artifactId> <type>pom</type> </dependency> <dependency> <groupId>org.apache.taglibs</groupId> <artifactId>taglibs-standard-impl</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.taglibs</groupId> <artifactId>taglibs-standard-spec</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>apache-jsp</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>apache-jstl</artifactId> <scope>compile</scope> </dependency> <dependency> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-annotations</artifactId> <scope>compile</scope> </dependency>

And if you're shading the WAR into a FAT jar, you're in for another world of pain if dependencies are scoped differently (compile vs runtime), then the order of dependencies matter or otherwise you'll start getting the same NullPointerException .而且,如果您将 WAR 隐藏到 FAT jar 中,如果依赖项的范围不同(编译与运行时),那么您将面临另一个痛苦的世界,那么依赖项的顺序很重要,否则您将开始获得相同的NullPointerException

I faced exactly the same issue when upgrading from Jetty 8.1 to 9.4.从 Jetty 8.1 升级到 9.4 时,我遇到了完全相同的问题。 In my case, it was not about missing dependencies, but too many or conflicting ones.就我而言,这不是缺少依赖项,而是太多或冲突的依赖项。 The issue went away after I removed the following artifacts from the classpath:在我从类路径中删除以下工件后,问题就消失了:

  • org.mortbay.jasper.apache-jsp org.mortbay.jasper.apache-jsp
  • org.mortbay.jasper.apache-el org.mortbay.jasper.apache-el

The Jetty Project maintains an example project for JSP use in embedded-jetty. Jetty 项目维护了一个用于 JSP 在嵌入式码头中使用的示例项目。

See: github.com/jetty-project/embedded-jetty-jsp请参阅: github.com/jetty-project/embedded-jetty-jsp

What you need to fix:您需要解决的问题:

  • Use a Build Tool!使用构建工具! (this is the most important aspect of this answer, this alone would have solved 3/4 of your issues) (这是此答案最重要的方面,仅此一项就可以解决您 3/4 的问题)
  • Fix your dependencies修复你的依赖

Example:例子:

[embedded-jetty-jsp]$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building embedded-jetty-jsp 1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ embedded-jetty-jsp ---
[INFO] org.eclipse.jetty.demo:embedded-jetty-jsp:jar:1-SNAPSHOT
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] +- org.eclipse.jetty:jetty-annotations:jar:9.3.3.v20150827:compile
[INFO] |  +- org.eclipse.jetty:jetty-plus:jar:9.3.3.v20150827:compile
[INFO] |  |  \- org.eclipse.jetty:jetty-jndi:jar:9.3.3.v20150827:compile
[INFO] |  +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] |  +- org.ow2.asm:asm:jar:5.0.1:compile
[INFO] |  \- org.ow2.asm:asm-commons:jar:5.0.1:compile
[INFO] |     \- org.ow2.asm:asm-tree:jar:5.0.1:compile
[INFO] +- org.eclipse.jetty:jetty-webapp:jar:9.3.3.v20150827:compile
[INFO] |  +- org.eclipse.jetty:jetty-xml:jar:9.3.3.v20150827:compile
[INFO] |  \- org.eclipse.jetty:jetty-servlet:jar:9.3.3.v20150827:compile
[INFO] |     \- org.eclipse.jetty:jetty-security:jar:9.3.3.v20150827:compile
[INFO] +- org.eclipse.jetty:apache-jsp:jar:9.3.3.v20150827:compile
[INFO] |  +- org.eclipse.jetty:jetty-util:jar:9.3.3.v20150827:compile
[INFO] |  +- org.eclipse.jetty:jetty-server:jar:9.3.3.v20150827:compile
[INFO] |  |  +- org.eclipse.jetty:jetty-http:jar:9.3.3.v20150827:compile
[INFO] |  |  \- org.eclipse.jetty:jetty-io:jar:9.3.3.v20150827:compile
[INFO] |  +- org.eclipse.jetty.toolchain:jetty-schemas:jar:3.1.M0:compile
[INFO] |  +- org.mortbay.jasper:apache-jsp:jar:8.0.23.M1:compile
[INFO] |  |  \- org.mortbay.jasper:apache-el:jar:8.0.23.M1:compile
[INFO] |  \- org.eclipse.jetty.orbit:org.eclipse.jdt.core:jar:3.8.2.v20130121:compile
[INFO] \- org.eclipse.jetty:apache-jstl:pom:9.3.3.v20150827:compile
[INFO]    +- org.apache.taglibs:taglibs-standard-spec:jar:1.2.1:compile
[INFO]    \- org.apache.taglibs:taglibs-standard-impl:jar:1.2.1:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.884 s
[INFO] Finished at: 2015-09-15T05:37:53-07:00
[INFO] Final Memory: 13M/481M
[INFO] ------------------------------------------------------------------------
  • Setup your JSP environment properly.正确设置您的 JSP 环境。

    Pay attention to:注意:

    • Instance Manager Setup实例管理器设置
    • Temp / Scratch Dir温度/划痕目录
    • ContainerIncludeJarPattern ContainerIncludeJarPattern
    • Container Initializers容器初始化器
    • JettyJasperInitializer JettyJasperInitializer
    • non-System ClassLoader requirement非系统类加载器要求
    • Setup of JasperServlet JasperServlet 的设置
    • Setup of DefaultServlet DefaultServlet 的设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM