С Java 1.6
, есть встроенный HTTP server
. Это один Example
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 {
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 {
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();
}
}
}
Выполнить его и перейти к http://localhost:8000/test
и вы увидите ответ
Кроме того, Jetty: Example
* «Исходный код или любое полезное учебное пособие будут очень полезны». * Было бы полезно показать усилия и задать (конкретный) вопрос. Как бы то ни было, это «не настоящий вопрос». –