Bonjour,
En Java il y a plein de frameworks qui permettent de faire des applications web.
On peut aussi faire son petit code à la main :
import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpServer; import java.io.IOException; import java.net.InetSocketAddress; public class TestServer { public static void main(String[] args) throws IOException { var server = HttpServer.create(new InetSocketAddress(8080), 0); server.createContext("/test", TestServer::handle); server.start(); } private static void handle(HttpExchange exchange) throws IOException { var body = new String(exchange.getRequestBody().readAllBytes()); var response = "Body : " + body; exchange.sendResponseHeaders(200, response.length()); exchange.getResponseBody().write(response.getBytes()); } }
Exemple :
<form action="http://localhost:8080/test" method="post"> <input type="text" id="firstname" name="firstname"> <input type="text" id="lastname" name="lastname"> <input type="submit" value="Submit"> </form>