sharpds77 发表于 2017-2-26 10:39:46

使用jetty默认启动

  我们的需求是这样的。通过程序来配置jetty的服务-启动。要直接在 浏览器中输入http://IP:8083. 
  ok。直接跳转到欢迎界面。下面来看如何来做。
  public void start() throws Exception {
  server.addListener(":" + this.port);
  HttpContext context = server.getContext("/index.html"); //关键部分,这里就是要在webapps下有一个 index.html.指向的就是这个html.当然也可以是其它的比如说:**.jsp
  WebApplicationHandler wah = new WebApplicationHandler();
  for (HttpHandler httpHandler : httpHandlers) {
   context.addHandler(httpHandler);
  }
  server.start();
  server.join();
  //这个方法主要是用来配置jetty服务启动的路径的。包括该路径下的jsp等
  public void addContext(String webappPath, String contextPath)
   throws Exception, IOException {
  ServletHttpContext hc = new ServletHttpContext();
  Resource rc = Resource.newResource(webappPath);
  hc.setBaseResource(rc);
  hc.setContextPath(contextPath);
  hc.addServlet("JSP", "*.jsp", "org.apache.jasper.servlet.JspServlet");
  hc.addHandler(new ResourceHandler());
  server.addContext(hc);
  }
 }
  都准备放弃明天搞了,
页: [1]
查看完整版本: 使用jetty默认启动