Skip to content

Instantly share code, notes, and snippets.

@tadams
Created September 4, 2015 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tadams/29bd899ad60538e64240 to your computer and use it in GitHub Desktop.
Save tadams/29bd899ad60538e64240 to your computer and use it in GitHub Desktop.
package org.example;
import com.sun.net.httpserver.HttpServer;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
public class HelloWeb {
public static void main(String[] args) throws Exception {
HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0);
server.setExecutor(Executors.newCachedThreadPool());
server.start();
server.createContext("/", httpExchange -> {
httpExchange.sendResponseHeaders(200, 0);
try (OutputStream out = httpExchange.getResponseBody()) {
out.write("Hello World".getBytes());
}
});
}
}
@tadams
Copy link
Author

tadams commented Sep 4, 2015

A small http server that returns Hello World ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment