vendredi 29 juillet 2016

Is the HttpsServer expandable with web-Gui?

I have created some https-server with java se and in future i want to create some small web gui, where you can see some database entries. My question is, is it possible and practical to make this small webgui with java se? or should i change maybe to java ee with spring framework?

I used following code as basics:

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();
    }
  }
}

Thank you a lot, Mira




Aucun commentaire:

Enregistrer un commentaire