• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • JDK6.0的新特性:輕量級Http Server

    發表于:2007-04-27來源:作者:點擊數: 標簽:httpJDK6.0新特性輕量級特性
    JDK6提供了一個簡單的Http Server API,據此我們可以構建自己的 嵌入式 Http Server,它支持Http和Https協議,提供了HTTP1.1的部分實現,沒有被實現的那部分可以通過擴展已有的Http Server API來實現, 程序員 必須自己實現HttpHandler接口,HttpServer會調用Http
      JDK6提供了一個簡單的Http Server API,據此我們可以構建自己的嵌入式Http Server,它支持Http和Https協議,提供了HTTP1.1的部分實現,沒有被實現的那部分可以通過擴展已有的Http Server API來實現,程序員必須自己實現HttpHandler接口,HttpServer會調用HttpHandler實現類的回調方法來處理客戶端請求,在這里,我們把一個Http請求和它的響應稱為一個交換,包裝成HttpExchange類,HttpServer負責將HttpExchange傳給HttpHandler實現類的回調方法.下面代碼演示了怎樣創建自己的Http Server

    /**
    * 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 = "<h3>Happy New Year 2007!--Chinajash</h3>";
      t.sendResponseHeaders(200, response.length());
      OutputStream os = t.getResponseBody();
      os.write(response.getBytes());
      os.close();
     }
    }

      查看關于 JDK6.0 的全部文檔     觀察:從老虎到野馬 Java 6.0新功能觀察 

    ·Java初學者專區  ·Java高級技術
    ·Java圖像與多媒體 ·Java網絡編程
    ·Eclipse ·Hibernate
    ·Spring ·Struts
    ·Java設計模式 ·EJB開發 

    原文轉自:http://www.kjueaiud.com

    評論列表(網友評論僅供網友表達個人看法,并不表明本站同意其觀點或證實其描述)
    ...
    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>