Jetty 嵌入:JSP 和 Servlet 结合在一起?
我有一个嵌入 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个路径组件应由其自己的上下文处理,并确保将 ContextHandlerCollection 用于多个上下文。
Each path component should be handled by its own context and make sure you use
ContextHandlerCollection
for multiple contexts.