Jetty服务器无法使用JSP进行War



我正在尝试创建一个简单的jetty服务器/容器,它将接受一个war文件并进行部署。这不是带弹簧靴的嵌入式码头。

这是我的build.gradle依赖项:

dependencies {
def jettyVersion = "9.4.34.v20201102"
implementation "org.eclipse.jetty:jetty-server:$jettyVersion"
implementation "org.eclipse.jetty:jetty-security:$jettyVersion"
implementation "org.eclipse.jetty:jetty-servlet:$jettyVersion"
implementation "org.eclipse.jetty:jetty-webapp:$jettyVersion"
implementation "org.eclipse.jetty:jetty-annotations:$jettyVersion"
implementation "org.eclipse.jetty:jetty-jmx:$jettyVersion"
}

这是我的主要课程:

public static void main(String[] args) throws Exception {
Server server = new Server(8080);
MBeanContainer mbContainer = new MBeanContainer(getPlatformMBeanServer());
server.addBean(mbContainer);
WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setWar(warFile()); // LOGIC TO UPLOAD WAR FILE
webapp.setExtractWAR(true);
Configuration.ClassList classList = Configuration.ClassList.setServerDefault(server);
classList.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
"org.eclipse.jetty.annotations.AnnotationConfiguration");
webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
".*/[^/]*servlet-api-[^/]*\.jar$|.*/javax.servlet.jsp.jstl-.*\.jar$|.*/[^/]*taglibs.*\.jar$");
server.setHandler(webapp);
server.start();
server.dumpStdErr();
server.join();
}

然而,当我尝试转到应用程序时(http://localhost:8080/index),我不断收到以下错误消息:

URI:    /index
STATUS: 500
MESSAGE:    JSP support not configured
SERVLET:    jsp

控制台中只有一行错误消息:

2020-12-11 09:49:51.563:INFO:oejshC.ROOT:qtp2025864991-33: No JSP support.  Check that JSP jars are in lib/jsp and that the JSP option has been specified to start.jar

它指的是什么JSP Jars?我不知道需要添加哪些依赖项才能使其适用于JSP。

Thx。

您必须添加apachejsp,这样您的服务器才能支持jsp。如果您的web应用程序使用jstl,您还应该添加apachejstl。

对于WebAppContext的使用(它比ServletContextHandler的使用更容易设置(,您需要以下工件。。。

  • https://search.maven.org/artifact/org.eclipse.jetty/apache-jsp(针对从JasperJspServlet延伸的码头专用JettyJspServlet(
  • https://search.maven.org/artifact/org.eclipse.jetty/apache-jstl(支持Taglib自定义和标准(

确保您的org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern可以正确地引用apachejsp工件,否则内部javax.servlet.ServletContextInitializer将无法正确加载。

如果简单地添加这些工件就没有任何结果,那么您需要在WebAppContext.setDefaultsDescriptor(String)上验证默认描述符设置,以确保将资源引用(路径或uri(传递给Jetty默认描述符XML。

https://github.com/eclipse/jetty.project/blob/jetty-9.4.35.v20201120/jetty-webapp/src/main/config/etc/webdefault.xml

如果使用ServletContextHandler而不是WebAppContext,那么在嵌入式模式下启用JSP支持可能会非常棘手。

如果您决定使用ServletContextHandler而不是WebAppContext(拥有一个fat/uuber jar,加快加载/部署时间,简化单元测试等(,请查看Jetty维护的示例项目。。。

https://github.com/jetty-project/embedded-jetty-jsp

最新更新