jetty+嵌入项目编程

=Don't deploy your application in Jetty, deploy Jetty in your application.=

按照以下步骤可以把jetty服务器嵌入到用户项目中：
 * 1) 创建一个server
 * 2) 添加并配置connectors
 * 3) 添加并配置Handlers
 * 4) 为Handlers添加并配置Servlets/Webapps
 * 5) 启动server
 * 6) ......(wait)

配置Handler
jetty需要一个Handler来响应请求，Handler可能会 现在写一个最简单的HelloHandler，代码如下： code format="java" public class HelloHandler 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 "); } } code 代码中参数解析： The handler sets the response status, content-type and marks the request as handled before it generates the body of the response using a writer. handler在响应以前设置响应状态、内容类型、标记请求，响应过程就是向页面写入字符“ Hello World ” 驱动代码如下： code format="java" public static void main(String[] args) throws Exception {   Server server = new Server(8080); server.setHandler(new HelloHandler);
 * 检查或者修改 HTTP request.
 * 产生完全的HTTP response.
 * 调用其他 Handler.
 * 选择一个或多个Handler来调用.
 * target–请求的目的地，可能是个URI或者命名调度器中的一个名称(a name from a named dispatcher).
 * baseRequest–jetty易变的请求对象，常常是不封装的(unwrapped).
 * request–请求对象，常常是封装的(wrapped).
 * response–响应,常常是封装的(wrapped).

server.start; server.join; } code

配置连接器
oo