繁体   English   中英

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

[英]Jetty embedded: JSP and Servlets together?

我有一个嵌入式Jetty 6.1.26的应用程序。 Servlet 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

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

每个路径组件都应由其自己的上下文处理,并确保对多个上下文使用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