简体   繁体   English

Jetty嵌入式:JSP和Servlet在一起?

[英]Jetty embedded: JSP and Servlets together?

I have an application with embedded Jetty 6.1.26. 我有一个嵌入式Jetty 6.1.26的应用程序。 Servlet 2.5. 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. 问题是,当我尝试将JSP和Servlet放在一起时,它不起作用。 I either have one or the other working, based on whether I have server.addHandler() or server.setHandler() in the code below. 根据我在下面的代码中是否有server.addHandler()server.setHandler() ,我有一个或另一个工作。

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). 通过“不工作”我的意思是Jetty返回404,但是否则看起来很好,甚至Jetty日志显示配置都很好 - 请参阅http://pastebin.com/PzbEx0qc (与addHandler()一起使用,JSP无效)。

The URLS requested are 请求的URL是
http://localhost:17283/jars?mvnPath= ... and http:// localhost:17283 / jars?mvnPath = ...和
http://localhost:17283/jsp/index.jsp . http:// localhost:17283 / jsp / index.jsp

Thanks, Ondra 谢谢,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" );

Each path component should be handled by its own context and make sure you use ContextHandlerCollection for multiple contexts. 每个路径组件都应由其自己的上下文处理,并确保对多个上下文使用ContextHandlerCollection

ContextHandlerCollection contexts = new ContextHandlerCollection();

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

server.setHandler(contexts);

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

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