leetcode题解


Jetty Hello World教程 2

关于如何在命令行下run一个Hello world的jetty程序。 首先下载两个依赖包 http://mvnrepository.com/artifact/javax.servlet/servlet-api/2.5 http://mvnrepository.com/artifact/org.eclipse.jetty.aggregate/jetty-all/7.0.2.v20100331 将它们放在一个文件夹下,然后新建一个HelloWorld.java的文件,填入如下代码: import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import java.io.IOException; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; public class HelloWorld 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(“<h1>Hello World</h1>”); } public static void main(String[] args) […]