分类: Web开发
2013-10-26 17:52:40
package com.google.code.garbagecan.jettystudy.sample1;
import org.eclipse.jetty.server.Server;
public class MyServer {
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
server.setHandler(new HelloHandler());
server.start();
server.join();
}
}
2.创建一个Handler类,用了处理所有客户端的请求
package com.google.code.garbagecan.jettystudy.sample1;
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 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("