/ Published in: Java
A simple http server, from java JDK.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
package com.example; 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 { 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 { t.sendResponseHeaders(200, response.length()); os.write(response.getBytes()); os.close(); } } }