HttpsServer是否可以通过web-Gui扩展?

时间:2016-07-29 08:21:44

标签: java web https

我用java se创建了一些https-server,将来我想创建一些小的web gui,你可以看到一些数据库条目。我的问题是,使用java se制作这个小的webgui是否可行和实用?或者我应该用spring框架改变java ee?

我使用以下代码作为基础:

package com.stackoverflow.q3732109;

import java.io.IOException;
import java.io.OutputStream;    
import java.net.InetSocketAddress;

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

public class Test {
 public static void main(String[] args) throws Exception {
    HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
    server.createContext("/test", new MyHandler());
    server.setExecutor(null); // creates a default executor
    server.start();
 }

 static class MyHandler implements HttpHandler {
    @Override
    public void handle(HttpExchange t) throws IOException {
        String response = "This is the response";
        t.sendResponseHeaders(200, response.length());
        OutputStream os = t.getResponseBody();
        os.write(response.getBytes());
        os.close();
    }
  }
}

非常感谢你,Mira

0 个答案:

没有答案