论坛首页 入门技术论坛

使用jetty默认启动

浏览 1527 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2010-02-03  

我们的需求是这样的。通过程序来配置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);

 }
 }

都准备放弃明天搞了,

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics