Web Server(Java)Socket, Java, and HTTP
A web server built with sockets in Java, capable of handling general HTTP requests.
This web server is able to handle HTTP requests from client(web browser) simultaneously. Java sockets are used to accept string-format requests, process them and return string-format responses. So, this web server processes standard HTTP requests and responses at socket level.
1. Web Server
Open web browser, access ‘http://localhost:2540/’. All of the files in the root directory are displayed.
1.2 Directory Navigation
Click on the folder ‘src’ and navigate to the deeper layers. The path in browser’s address bar changes accordingly, files in each directory are properly displayed.
1.3 Viewing File Content
Click on file ‘WebServer.java’, its content shows up. Go back to the root folder, view content of txt file.
1.4 Viewing HTML Page
Apart from handling the requests to static files and directories, this web server also supports to handle dynamical requests. For example, it has a fake CGI page which can calculate the sum of two given numbers. In the root directory, click ‘addnums.html’. Specify the name and two numbers, click Submit button. If numbers are correctly set, we can get the proper result.
1.6 Error Handling
If invalid input are passed to the server, it returns 500 error with specific error message.
Check the logs in WebServerLogs.txt. These logs are also available in the console of Eclipse.
2. Under the Hood
Check posting Building Web Server with Java Socket to learn the details how this web server is built.