all


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) […]


[leetcode] Count Primes

Count Primes Description: Count the number of prime numbers less than a non-negative number, n. Credits: Special thanks to @mithmatt for adding this problem and creating all test cases. A naive approach, check each i smaller than n that is prime or not. O(n^2), time limit exceeded. class Solution { […]


Word Pattern I && II

Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str. Examples: pattern = “abba”, str = “dog cat cat dog” should return true. […]


[lintcode] Expression Tree Build

Expression Tree Build The structure of Expression Tree is a binary tree to evaluate certain expressions. All leaves of the Expression Tree have an number string value. All non-leaves of the Expression Tree have an operator string value. Now, given an expression array, build the expression tree of this expression, […]