首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jetty不与JSP协同工作

Jetty不与JSP协同工作
EN

Stack Overflow用户
提问于 2020-12-11 16:56:20
回答 2查看 475关注 0票数 0

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

下面是我的build.gradle依赖关系:

代码语言:javascript
复制
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"
}

这是我的主修课:

代码语言:javascript
复制
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)时,我一直收到以下错误消息:

代码语言:javascript
复制
URI:    /index
STATUS: 500
MESSAGE:    JSP support not configured
SERVLET:    jsp

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

代码语言:javascript
复制
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上工作,我感到困惑。

谢谢。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-12-11 17:02:52

您必须添加apache,以便您的服务器能够支持jsps。如果您的web应用程序使用jstl,则还应该添加apache。

票数 0
EN

Stack Overflow用户

发布于 2020-12-11 17:17:03

对于WebAppContext使用(这比ServletContextHandler使用要容易一些),您将需要以下构件.

扩展而来。

确保您的org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern能够正确引用apache工件,否则内部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/uber jar,以加快加载/部署时间,简化单元测试等等),那么请查看Jetty维护的示例项目。

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65255476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档