What's the easiest way to create a simple HTTP server with Java? Are there any libraries in commons to facilitate this? I only need to respond to GET/POST
, and I can't use an application server.
What's the easiest way to accomplish this?
What's the easiest way to create a simple HTTP server with Java? Are there any libraries in commons to facilitate this? I only need to respond to GET/POST
, and I can't use an application server.
What's the easiest way to accomplish this?
If you are using the Sun JDK you can use this built in library
Look at this site on how to use.
If n ot there are several Open Source HTTP Servers here which you can embed into your software.
Use Jetty.
Jetty is pretty lightweight but it does provide a servlet container which may contradict your requirement against using an "application server".
A servlet container is definitely the way to go. If Tomcat or Jetty are too heavyweight for you, consider Winstone or TTiny.
This is how I would go about this:
ServerSocket
listening (probably on port 80).ServerSocket
available to keep listening and accept other connections).Content-Type
, etc.) and the HTML.I find it useful to use Firebug (in Firefox) to see examples of headers. This is what you want to emulate.
Try this link: - Multi-threaded HTTP Server Example (Java)