Examples for Java Servlets
After we have learned about sockets and HTML, we are able to develop nice web pages and we can also send data over the internet using TCP. It may occur to us that a web server is actually just sending HTML and stuff over the net, using sockets. The web browser then receives the data and displays it. Of course, they cannot just use TCP for communication, as the web browser must somehow tell the web server which page or which image (hosted on that server) it wants and the web server needs to say whether the request was successful or not and so on. For this, the hypertext transfer protocol exist. This protocol is sent via TCP and it is text-based. With the stuff we have learned, we can fully implement it. Actually, we already have done some partial, rudimentary implementations of it in the sockets examples set.
Still, doing this by hand is not just cumbersome, we will probably make many mistakes. What we would like to have is an API for HTTP as comfortable as sockets are for TCP and UDP. Java Servlets are this kind of thing. A servlet is a sub-class of a special Java class which implements handler methods for different HTTP interactions ("HTTP methods"). These methods are called by a servlet container, the actual implementation of the server, which then uses sockets, thread pools, and also takes care of the character encoding for us. We can therefore fully concentrate on the application logic and don't need to worry about the protocol interaction itself.
Long story short, here you can find my Java Servlets examples.
This work has purely educational purposes. Besides everything mentioned below, for anything in this repository and projects, I impose one additional licensing condition: The code must never be used for anything which might violate the laws of Germany, China, or the USA. This also holds for any other file or resource provided here.
The examples in this repository are licensed under the GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007, with the exception of everything in the directories /javaServerPages/standAloneJSPsWithJetty and /javaServlets/proxy, which re licensed under the Apache License v2.0 and are partially derived from project embedded-jetty-jsp with copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.