Servlets / JSP TutorSJSP Home
The aim of this site is to cover the complete spectrum of server side to client side programming. The site is split into two sections covering development, persistence and presentation of data on the server side and development and presentation on the client side. All the individual disciplines come with quick references, case studies and quizzes to support and enhance overall learning and can be accessed from the relevant sections by using the appropriate tabs.
Server Side Programming
This part of the site covers server side programming development, persistence and presentation of data. Client-server programming of this sort can at first appear complicated because of all the components present in the different layers of a distributed system. From a logical viewpoint we can think of the different layers that make up the disparate parts of a distributed system as different tiers of an overall architecture. This way of conceptualizing a system is often referred to as a multi-tier architecture.
Three-Tier Architecture
The most common form of the multi-tier architecture paradigm is known as the three-tier architecture model and this is the architecture pattern used for this site. The three-tier architecture model separates our client-server programming into three tiers consisting of a presentation tier, an application tier and a data tier. Each tier is developed and maintained as an independent area of work and the different tiers can, and often do, exist on different software platforms. This separation of concerns reduces the complexity of the overall architecture and means any of the tiers can be modifed or even replaced with different technologies independently and without affecting the other tiers. The following diagram is a representation of a three-tier architecture model to aid in understanding of the concept:

How Servlets / JSP Tutor Fits into The Model
We make a through investigation of server side dynamic page loading using Java Servlets and JavaServer Pages (JSP), which the Tomcat Server stores in a JSP container that is translated to a Java class before being executed within the JRE. Persistence of data will be achieved using MySQL which we will connect to using JDBC4. Although we won't use an IDE for our development, we will do a few lessons on integrating the Tomcat Server into Eclipse. The following diagram shows how the disciplines for this section of the site fit into our three-tier architecture:

Discipline Correlation
The disciplines used have a correalation to the version of Java being used. This can get very confusing and so the table below shows which releases of software work with a particular version of Java:
Minimum Java Version | Tomcat Version | Servlets | JSP | EL | JSTL Tags |
---|---|---|---|---|---|
5 | 6.0.x | 2.5 | 2.1 | 2.1 | 1.2 |
6 | 7.0.x | 3.0 | 2.2 | 2.2 | 1.2.1 |
7 | 8.0.x | 3.1 | 2.3 | 3.0 | 1.2.1 |
ServletsS2C Home
We can think of a servlet as a Java class which we can use to extend the capabilities of an application server. Servlets have the capability to respond to any types of request but are commonly used to extend applications hosted by web servers such as Tomcat. Servlets give us the ability to serve dynamic web content to users from a container within our web server and are generally used with the HTTP protocol.
The following table shows the correalation between the Servlets, JSP, Tomcat and Java versions used on this site:
Servlets | JSP | Tomcat Version | Minimum Java Version |
---|---|---|---|
2.5 | 2.1 | 6.0.x | 5 |
3.0 | 2.2 | 7.0.x | 6 |
3.1 | 2.3 | 8.0.x | 7 |
Servlets 2.5 Basics
In this section we look at using servlets and will be covering the 2.5 release. We start the section by getting our environment ready for use with the servlets 2.5 specification. The first thing we do is download
the java SDK and set a relevant classpath for this. After this we download, verify and install Tomcat 6 to use in combination with our servlet
2.5 classes. A basic understanding of how the HTTP protocol works will give us a better understanding of how servlets are invoked so we talk about the HTTP protocol, the HTTP request/response
mechanism, HTTP methods and HTTP response codes. After this we learn about the Java EE5 Platform and how servlets fit into the architecture before starting our in depth investigation of servlets by looking at
the java interfaces and classes we need to create our own servlets. We follow our introduction servlets by looking at the servlet lifecycle and then writing our first servlet and then investigate the
ServletConfig
and ServletContext
objects that every servlet gets access to after initialisation. We finish the basics section by taking a detailed look at the request and response objects.
Servlets 2.5 Intermediate
In the first lesson of the Servlets 2.5 Intermediate section we learn how to create HTML forms, interrogate field values passed back to our servlets from HTML forms and how to action an appropriate response to form
input. After this in the first of three lessons on conversational state we look at two ways to get around the statelessness of HTTP and the pros and cons of the session management techniques used to do this. First
we will look at URL rewriting and then look at the use of hidden fields to achieve conversational state within our applications. In our second lesson on session management we look at cookies, the first of two tracking
techniques that are more flexible and work with web applications regardless of page volume. In our final lesson on session management we look at the HttpSession
interface and how we can use objects of this
type for session tracking. We then look at the three scopes our servlets can have, these being from narrowest to broadest, request, session and context and the attributes associated with them. Following on from our
discussion on scopes we discuss multithreading in web applications, whether a scope is thread safe, and if not, when and how we can protect resources within that scope from concurrent access. We finsih the section
by looking at redirects and request dispatching.
Servlets 2.5 Advanced
In the first three lessons of the section we do a detailed investigation of context, request and session listeners. After this we look at filters which are Java components that allow us to receive requests and responses and manipulate them through the filtering mechanism. We then investigate wrappers which allow us to create custom requests and responses and look at the Servlet API interfaces that can be subclassed by developers wishing to modify the request or response object. We finish the section with an in-depth look at declarative and programmatic security and how we can use these techniques to secure our web applications.
Servlets 3.0
In this section we look at using servlets and will be covering the 3.0 release. We start the section by getting our environment ready for use with the servlets 3.0 specification. The first thing we do is download the java SDK and set a relevant classpath for this. After this we download, verify and install Tomcat 7 to use in combination with our servlet 3.0 classes.
Servlets 3.1
In this section we look at using servlets and will be covering the 3.1 release. We start the section by getting our environment ready for use with the servlets 3.1 specification. The first thing we do is download the java SDK and set a relevant classpath for this. After this we download, verify and install Tomcat 8 to use in combination with our servlet 3.1 classes.
JSPS2C Home
We use Java Server Pages, more commonly known by the acronym JSP to present data to our users.
Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies and as we will be using servlets and JSPs in sections of this site, we will also be using Tomcat. The version of Tomcat we will be using is dependant upon the version of Servlets/JSP we are using. The following table shows the correalation between the JSP, Servlets, Tomcat and Java versions used on this site:
JSP | Servlets | Tomcat Version | Minimum Java Version |
---|---|---|---|
2.1 | 2.5 | 6.0.x | 5 |
2.2 | 3.0 | 7.0.x | 6 |
2.3 | 3.1 | 8.0.x | 7 |
JSP 2.1
In this section we look at using JavaServer Pages (JSPs) and will be covering the 2.1 release. You need to have an understanding of Java and Servlets to get the most from these lessons, so if you're completely new to Java I suggest going to the Java 8 Tutorials site and doing the lessons there first. If you're new to Servlets you would be better doing the lessons in the Sevlets 2.5 section of the site first.
The following link will take you to the download page for the final release specification for the JSP 2.1 release which you can download and read at your leisure, JSR-245 specification.
For us to use JSPs we need a Java SDK; details of downloading and installing this are given in the Introduction to Servlets 2.5 lesson and a Servlet/JSP compliant web container to host our JSPs on; details of downloading and installing this are given in the Getting Tomcat 6 lesson.
We start the section by discussing why JSPs are used and how they complement Java and Servlets and outline the interface and class hierarchy used with JSPs. We then make a much deeper inpsection of JSPs by looking at the JSP lifecycle and the mechanics of how a JSP is translated into a full-blown servlet. After this we look at the anatomy of JSP by investigating the various components that can be used within a JSP page and then look at the implicit objects we can use within our JSP pages. In the fifth and sixth lessons we investigative the directives and scripting elements available when constructing our JSP pages. We finish our discussion of JSPs with two lessons on the standard actions we can use when creating our JSP pages.
JSP 2.2
In this section of the site we will be downloading, verifying and installing Tomcat 7 to use in combination with our servlet 3.0 classes and JSP 2.2 pages. After installing Tomcat 7, we look at starting up, testing and shutting down the Tomcat 7 server gracefully.
JSP 2.3
In this section of the site we will be downloading, verifying and installing Tomcat 8 to use in combination with our servlet 3.1 classes and JSP 2.3 pages. After installing Tomcat 8, we look at starting up, testing and shutting down the Tomcat 8 server gracefully.
ServersS2C Home
Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies and as we will be using servlets and JSPs in sections of this site, we will also be using Tomcat. The version of Tomcat we will be using is dependant upon the version of Servlets/JSP we are using. The following table shows the correalation between the Tomcat, Servlets, JSP and Java versions used on this site:
Tomcat Version | Servlets | JSP | Minimum Java Version |
---|---|---|---|
6.0.x | 2.5 | 2.1 | 5 |
7.0.x | 3.0 | 2.2 | 6 |
8.0.x | 3.1 | 2.3 | 7 |
Tomcat 6
In this section of the site we will be downloading, verifying and installing Tomcat 6 to use in combination with our servlet 2.5 classes and JSP 2.1 pages. After installing Tomcat 6, we look at starting up, testing and shutting down the Tomcat 6 server gracefully.
Tomcat 7
In this section of the site we will be downloading, verifying and installing Tomcat 7 to use in combination with our servlet 3.0 classes and JSP 2.2 pages. After installing Tomcat 7, we look at starting up, testing and shutting down the Tomcat 7 server gracefully.
Tomcat 8
In this section of the site we will be downloading, verifying and installing Tomcat 8 to use in combination with our servlet 3.1 classes and JSP 2.3 pages. After installing Tomcat 8, we look at starting up, testing and shutting down the Tomcat 8 server gracefully.
The Eclipse IDES2C Home
Integrated Develpoments Environments, more commonly known by the acronym IDE can really help us develop complex architectures and take a lot of mundane tasks out of our hands. In this part of the site we look at one of the most popular freeware IDEs Eclipse and see how we can perform various tasks.
Getting Started With Eclipse
In these lessons we download the latest version of Eclipse and set up our development environment.