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
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: - Multithreaded Server in Java
Embedding Tomcat is relatively painless as such things go. Here's a good StackOverflow reference about it.
I have implemented one link
N.B. for processing json, i used jackson. You can remove that also, if you need
I just added a public repo with a ready to run out of the box server using Jetty and JDBC to get your project started.
Pull from github here: https://github.com/waf04/WAF-Simple-JAVA-HTTP-MYSQL-Server.git
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.
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.