Jetty 嵌入:JSP 和 Servlet 结合在一起?

发布于 2024-10-01 16:54:42 字数 1597 浏览 1 评论 0原文

我有一个嵌入 Jetty 6.1.26 的应用程序。服务程序 2.5。 以下是我的服务器配置。

问题是,当我尝试将 JSP 和 Servlet 结合在一起时,它不起作用。根据下面的代码中是否有 server.addHandler()server.setHandler() ,我可以使用其中之一。

我所说的“不起作用”是指 Jetty 返回 404,但除此之外它看起来还不错,甚至 Jetty 日志也显示配置正常 - 请参阅 http://pastebin.com/PzbEx0qc (使用 addHandler() 时,JSP 不起作用)。

请求的 URL 为
http://localhost:17283/jars?mvnPath=... 和
http://localhost:17283/jsp/index.jsp

谢谢, 翁德拉

Server server = new Server( PORT );
Context ctx = new Context( server, "/", Context.NO_SECURITY | Context.SESSIONS );


final String WEBAPP_RESOURCES_PATH = "org/jboss/qa/mavenhoe/web/jsp";
final String JSP_CONTEXT_PATH = "/jsp";

// For localhost:port/jsp/index.html and whatever else is in the directory...
final URL warUrl = this.getClass().getClassLoader().getResource(WEBAPP_RESOURCES_PATH);
final String warUrlString = warUrl.toExternalForm();
    WebAppContext webAppContext = new WebAppContext(warUrlString, JSP_CONTEXT_PATH);
webAppContext.setAttribute("jarIndex", jarIndex);
server.addHandler( webAppContext );


// .jar's download.
final ServletHolder mavenhoeSH = new ServletHolder(new JarFinderServlet(this.jarIndex));
ctx.addServlet( mavenhoeSH, "/jars" );


final ServletHolder shutdownSH = new ServletHolder(new JettyShutdownServlet( server ));
shutdownSH.checkServletType();
ctx.addServlet( shutdownSH, "/shutdown" );

I have an application with embedded Jetty 6.1.26. Servlet 2.5.
Below is my server configuration.

The problem is, that when I try to have JSPs and Servlets together, it does not work. I either have one or the other working, based on whether I have server.addHandler() or server.setHandler() in the code below.

By "does not work" I mean that Jetty returns 404, but otherwise it looks fine, even Jetty log shows the configuration went fine - see http://pastebin.com/PzbEx0qc (that was with addHandler(), JSP was not working).

The URLS requested are
http://localhost:17283/jars?mvnPath=... and
http://localhost:17283/jsp/index.jsp .

Thanks,
Ondra

Server server = new Server( PORT );
Context ctx = new Context( server, "/", Context.NO_SECURITY | Context.SESSIONS );


final String WEBAPP_RESOURCES_PATH = "org/jboss/qa/mavenhoe/web/jsp";
final String JSP_CONTEXT_PATH = "/jsp";

// For localhost:port/jsp/index.html and whatever else is in the directory...
final URL warUrl = this.getClass().getClassLoader().getResource(WEBAPP_RESOURCES_PATH);
final String warUrlString = warUrl.toExternalForm();
    WebAppContext webAppContext = new WebAppContext(warUrlString, JSP_CONTEXT_PATH);
webAppContext.setAttribute("jarIndex", jarIndex);
server.addHandler( webAppContext );


// .jar's download.
final ServletHolder mavenhoeSH = new ServletHolder(new JarFinderServlet(this.jarIndex));
ctx.addServlet( mavenhoeSH, "/jars" );


final ServletHolder shutdownSH = new ServletHolder(new JettyShutdownServlet( server ));
shutdownSH.checkServletType();
ctx.addServlet( shutdownSH, "/shutdown" );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半步萧音过轻尘 2024-10-08 16:54:42

每个路径组件应由其自己的上下文处理,并确保将 ContextHandlerCollection 用于多个上下文。

ContextHandlerCollection contexts = new ContextHandlerCollection();

contexts.setHandlers(new Handler[] { jspContext, servletContext });

server.setHandler(contexts);

Each path component should be handled by its own context and make sure you use ContextHandlerCollection for multiple contexts.

ContextHandlerCollection contexts = new ContextHandlerCollection();

contexts.setHandlers(new Handler[] { jspContext, servletContext });

server.setHandler(contexts);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文