Filed Under (Servlets) by admin on 03-01-2011
Before we can start writing the first Servlet, we need to know some basics of HTTP (“HyperText Transfer Protocol”), the protocol which is used by a WWW client (e.g. a browser) to send a request to a Web Server.
HTTP is a request-response oriented protocol. An HTTP request consists of a request method, a URI, header [...]
Filed Under (Servlets) by admin on 03-01-2011
A Servlet, in its most general form, is an instance of a class which implements the javax.servlet.Servlet interface. Most Servlets, however, extend one of the standard implementations of that interface, namely javax.servlet.GenericServlet and javax.servlet.http.HttpServlet. In this tutorial we’ll be discussing only HTTP Servlets which extend the javax.servlet.http.HttpServlet class.
In order to initialize a Servlet, a server [...]
Filed Under (Servlets) by admin on 03-01-2011
This section shows how to
send binary data with a Servlet
A Servlet can not only return HTML pages but any kind of text or binary data. Apart from creating dynamic HTML pages and returning data which is stored on disk another common use for Servlets is creating dynamic images. The images can use any format [...]
Filed Under (Servlets) by admin on 03-01-2011
This section shows how to
use Session Tracking capabilities
Session Tracking allows a Servlet to associate a request with a user. A session can extend across requests and connections of the stateless HTTP. Sessions can be maintained in two ways:
By using Cookies. A Cookie is a string (in this case that [...]
Filed Under (Servlets) by admin on 03-01-2011
This section shows how to
process form data
manage persistent data
use init parameters
The next Servlet that we are going to write provides a user interface to a mailing list through HTML forms. A user should be able to enter an email address in a text field and press a button to subscribe to the [...]
Filed Under (Servlets) by admin on 03-01-2011
This section shows how to
use the framework that makes up a simple Servlet
write a Servlet that provides static content (i.e. it produces the same output every time it is called by a client)
We start our venture into Servlet programming with the well-known “Hello World” example, this [...]
Filed Under (Servlets) by admin on 03-01-2011
This section shows how to
share data between Servlets
Version 2.1 of the Servlet API offers a new way of sharing named objects between all the Servlets in a Servlet context (and also other contexts, as you’ll see below) by binding the objects to the ServletContext object which is shared by several Servlets.
The ServletContext class has [...]
Filed Under (Servlets) by admin on 03-01-2011
This section shows how to
access resources which belong to a Servlet
A Servlet may need to access additional resources like configuration files whose locations should not need to be specified in init parameters. Those resources can be accessed with the methods getResource(String name) and getResourceAsStream(String name) of the java.lang.Class object which represents the Servlet’s class.
Example. [...]
Filed Under (Servlets) by admin on 03-01-2011
This section shows how to
call another Servlet (or any other kind of active resource) to process a request
A Servlet can make a request to an active resource on the web server just like a client can (by requesting a URL). The Servlet API supports a more direct [...]
Filed Under (Servlets) by admin on 03-01-2011
This section shows how to
call a method of another Servlet
The inter-Servlet communication method which is described in this section can only be used with Servlet engines which implement version 1.0 or 2.0 of the Servlet API. It will not work with Servlet engines which comply strictly to version 2.1. The new way of doing [...]