分类: Web开发
2013-10-26 18:11:29
package com.google.code.garbagecan.jettystudy.sample4;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MyServer {
public static void main(String[] args) throws Exception {
new ClassPathXmlApplicationContext("/com/google/code/garbagecan/jettystudy/sample4/spring.xml");
}
}
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("
xsi:schemaLocation=" ">
其中定义了Jetty Server的配置,包括Connector和Handler等等。
5. 运行MyServer类,然后通过来访问。