Chinaunix首页 | 论坛 | 博客
  • 博客访问: 579859
  • 博文数量: 718
  • 博客积分: 4000
  • 博客等级: 上校
  • 技术积分: 4960
  • 用 户 组: 普通用户
  • 注册时间: 2008-10-17 13:24
文章分类

全部博文(718)

文章存档

2011年(1)

2008年(717)

我的朋友

分类:

2008-10-17 13:34:14

/**
* Created by IntelliJ IDEA.
* User: Chinajash
* Date: Dec 30, 2006
*/
public class HTTPServerAPITester {
 public static void main(String[] args) {
  try {
   HttpServer hs = HttpServer.create(new InetSocketAddress(8888),0);//设置HttpServer的端口为8888
   hs.createContext("/chinajash", new MyHandler());//用MyHandler类内处理到/chinajash的请求
   hs.setExecutor(null); // creates a default executor
   hs.start();
  } catch (IOException e) {
   e.printStackTrace();
  }
 }
}

class MyHandler implements HttpHandler {
 public void handle(HttpExchange t) throws IOException {
  InputStream is = t.getRequestBody();
  String response = "

Happy New Year 2007!--Chinajash

";
  t.sendResponseHeaders(200, response.length());
  OutputStream os = t.getResponseBody();
  os.write(response.getBytes());
  os.close();
 }
}
--------------------next---------------------

阅读(292) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~