1 import java.io.PrintWriter; 2 import java.net.ServerSocket; 3 import java.net.Socket; 4 5 public class Test { 6 public static void main(String[] args) throws Exception { 7 ServerSocket server = new ServerSocket(8888); 8 while (true) { 9 Socket s = server.accept(); 10 Processer p = new Processer(s); 11 Thread t = new Thread(p); 12 t.start(); 13 } 14 } 15 } 16 17 class Processer implements Runnable { 18 private Socket socket; 19 20 public Processer(Socket s) { // TODO Auto-generated constructor stub 21 this.socket = s; 22 } 23 24 @Override 25 public void run() { 26 try { 27 PrintWriter out = new PrintWriter(socket.getOutputStream(), true); 28 out.println("HTTP/1.0 200 OK"); 29 out.println("Content-Type:text/html;charset=utf-8"); 30 out.println(); 31 out.println("<h1> Web test is OK </h1>"); 32 out.close(); 33 } catch (Exception ex) { 34 ex.printStackTrace(); 35 } finally { 36 try { 37 socket.close(); 38 } catch (Exception e) { 39 e.printStackTrace(); 40 } 41 } 42 } 43 }