【问题标题】:Jetty embedded: JSP and Servlets together?Jetty 嵌入:JSP 和 Servlet 在一起?
【发布时间】:2011-05-09 09:06:04
【问题描述】:

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

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

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

请求的网址是
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" );

【问题讨论】:

    标签: java jsp servlets jetty


    【解决方案1】:

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

    ContextHandlerCollection contexts = new ContextHandlerCollection();
    
    contexts.setHandlers(new Handler[] { jspContext, servletContext });
    
    server.setHandler(contexts);
    

    【讨论】:

      猜你喜欢
      • 2021-04-03
      • 1970-01-01
      • 1970-01-01
      • 2014-02-09
      • 2011-07-20
      • 2015-06-24
      • 1970-01-01
      • 2013-06-19
      • 1970-01-01
      相关资源
      最近更新 更多