|
Java - Web
Server
Note:
When I first implemented ContentHandlerImpl class, I named it HTMLHandler
(implements ContentHandler) which only handles HTML to be written
back on to the OutputStream. Thus for each content type I had to create
new Handler (e.g. JPEGHandler, GIFHandler, etc). However, I made this
big mistake of using character based output writer to write out the response
(which happens to work for HTMLHandler because text/html is TEXT). All
the binary contents such as jpeg and gifs did not get displayed corretly
on the browser due to this bug. It turned out that I had to use byte[]
to store the read contents rather than String.
I hope you
gained some insights about how you could write your own webserver. Please
feel free to send me comments and questions.
To Do:
- Performance
Tuning
- Full HTTP1.0/1.1
functionality implementation
- Pooling
of ContentHandler Object
- More configuration
parameters
Download:
Back to Main
|