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?
|
Use Jetty. Jetty is pretty lightweight but it does provide a servlet container which may contradict your requirement against using an "application server". |
|||||||
|
This is how I would go about this:
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) |
|||
|
The easiest is Simple there is a tutorial, no WEB-INF not Servlet API no dependencies. Just a simple lightweight HTTP server in a single JAR. |
|||
|
If you are using the Sun JDK you can use this built in library If n ot there are several Open Source HTTP Servers here which you can embed into your software. |
||||
|
Jetty is a great way to easily embed an HTTP server. It supports it's own simple way to attach handlers and is a full J2EE app server if you need more functionality. |
|||
|
I wrote a tutorial explaining how to write a simple HTTP server a while back in Java. Explains what the code is doing and why the server is written that way as the tutorial progresses. Might be useful http://kcd.sytes.net/articles/simple_web_server.php |
|||
|
Embedding Tomcat is relatively painless as such things go. Here's a good StackOverflow reference about it. |
|||
|
A servlet container is definitely the way to go. If Tomcat or Jetty are too heavyweight for you, consider Winstone or TTiny. |
|||
|
Java 6 has a default embedded http server. By the way, if you plan to have a rest web service, here is a simple example using jersey. |
|||
|