How to Create Simple HTTP Server in Java

Create Simple HTTP Server in Java

In this example, We will show you about, How to create simple http server in Java. The example has been tested with environment and output is shared in the same post.

We have lots of famous servers(HTTP) such as Tomcat, JBoss, and etc.. So is it possible for us to create simple HTTP server in java? Yes we can able to do it. lets create our own simple http server in java with following step by step procedures.

1) Project Structure

Create Simple HTTP Server in Java

Note: You can able to find rt.jar file inside the folder of JRE installed (ie: {JAVA_HOME}\jdk\jre\lib\rt.jar) on your machine. Once you found that add the jar file to lib folder of your project and set the classpath using eclipse tool or through command line.

2) Creating Server and Request Handler

3) Response Pages

4) Publishing the Server

5) Download Source Code

You can able to download the entire example source code here

Output

The following output will give you idea about, How to create simple http server in java.

How to Create Simple HTTP Server in Java

How to Create Simple HTTP Server in Java

References

1. Java™ HTTP Server Documentation
2. Java HttpServer API
3. Java HttpExchage API
4. Java Httphandler API