|
| 1 | +import com.sun.net.httpserver.HttpServer; |
| 2 | +import com.sun.net.httpserver.HttpHandler; |
| 3 | +import com.sun.net.httpserver.HttpExchange; |
| 4 | + |
| 5 | +import java.io.IOException; |
| 6 | +import java.io.OutputStream; |
| 7 | +import java.net.InetSocketAddress; |
| 8 | + |
| 9 | +public class EducationWebPage { |
| 10 | + public static void main(String[] args) throws IOException { |
| 11 | + int serverPort = 8000; // Port number for the server to listen on |
| 12 | + HttpServer server = HttpServer.create(new InetSocketAddress(serverPort), 0); |
| 13 | + |
| 14 | + server.createContext("/", new RootHandler()); // Handle requests to "/" |
| 15 | + |
| 16 | + server.setExecutor(null); // Use default executor |
| 17 | + |
| 18 | + System.out.println("Starting server on port " + serverPort + "..."); |
| 19 | + server.start(); |
| 20 | + } |
| 21 | + |
| 22 | + static class RootHandler implements HttpHandler { |
| 23 | + @Override |
| 24 | + public void handle(HttpExchange exchange) throws IOException { |
| 25 | + // HTML content for the webpage |
| 26 | + String response = "<html>\n" + |
| 27 | + "<head><title>Education</title></head>\n" + |
| 28 | + "<body>\n" + |
| 29 | + "<h1>Education</h1>\n" + |
| 30 | + "<p>Education is the process of acquiring knowledge, skills, values, beliefs, and habits. " + |
| 31 | + "It is a lifelong process that begins in early childhood and continues throughout one's life. " + |
| 32 | + "Education can take place in formal settings such as schools and universities, as well as through " + |
| 33 | + "informal means like self-study and experience.</p>\n" + |
| 34 | + "<p>In today's world, education is essential for personal development, social progress, " + |
| 35 | + "and economic growth. It empowers individuals to achieve their goals, contribute to society, " + |
| 36 | + "and adapt to a rapidly changing global environment.</p>\n" + |
| 37 | + "</body>\n" + |
| 38 | + "</html>"; |
| 39 | + |
| 40 | + // Set the response headers and send the response |
| 41 | + exchange.sendResponseHeaders(200, response.getBytes().length); |
| 42 | + OutputStream os = exchange.getResponseBody(); |
| 43 | + os.write(response.getBytes()); |
| 44 | + os.close(); |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments