Java SE - a small program for web servers

I'm just wondering how to implement a small server program in Java SE?

The program listens on port 80 and is ready to retrieve the InputStream object, but is there any function I can use to convert the InputStream to an HttpRequest object (something like Servlet)?

After that, how can I create an HttpResponse object and send the data back to the browser?

In conclusion, I'm just looking for any infrastructure that can help me parse the HTTP format in an object or from an object into an HTTP response stream.

(I know Java EE will be the best solution, I just want to test something in Java SE)

+7
source share
5 answers

In this case, do not watch Jetty . This is written precisely because purpouse is an implementation of an HTTP server in your application. But you probably won't get an HttpRequest object, but maybe something similar that should suit your needs.

+8
source

If you have an InputStream and just need to process the request / response format, see Apache HttpComponents

See here for more details: https://stackoverflow.com/a/316677/

+3
source

A really lightweight servlet container that is very suitable for embedding , Winstone .

+2
source

If you need a servlet implementation, look at Tomcat: http://tomcat.apache.org/

0
source

If you are looking for something very lightweight and flexible, you can take a look at Netty

https://netty.io/Documentation/WebHome

Personally, it was a little difficult for me to start, but as soon as the initial obstacle was overcome, it was powerful enough.

0
source

All Articles