http://blog.csdn.net/kongxx/article/details/7227107
Jetty实战之 嵌入式Jetty集成Spring运行
1.创建一个Server类,用来通过spring来启动Jetty server

package com.google.code.garbagecan.jettystudy.sample4;

import org.springframework.context.support.ClassPath

public class MyServer {
 public static void main(String[] args) throws Exception {
  new ClassPath }
}
2.创建一个Handler类,用了处理http请求

package com.google.code.garbagecan.jettystudy.sample4;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;

public class MyHandler extends AbstractHandler {
 public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
   throws IOException, ServletException {
  response.setContentType("text/html;charset=utf-8");
  response.setStatus(HttpServletResponse.SC_OK);
  baseRequest.setHandled(true);
  response.getWriter().println("

Hello World

");
  response.getWriter().println("
  • Request url: " + target + "
  • ");
      response.getWriter().println("
  • Server port: " + request.getServerPort() + "
  • ");
     }
    }
    3.创建一个spring配置文件,并放在com/google/code/garbagecan/jettystudy/sample4/spring.


    其中定义了Jetty Server的配置,包括Connector和Handler等等。
    5. 运行MyServer类,然后通过http://localhost:8080/来访问。

    10-30 00:58