table of contents

Advanced Servlet and JSP Tutorials

Interested in live training from the author of these tutorials?
See the upcoming public servlet & JSP course in Maryland
or contact hall@coreservlets.com for information
on a customized onsite version at your location.

The advanced tutorials on this page were originally based on Marty's book More Servlets and JavaServer Pages, but have evolved significantly to incorporate new technologies and approaches. They have been tested by Marty in live training courses in the US, Canada, Australia, Puerto Rico, Japan, Mexico, and the Philippines. Also see the beginning and intermediate servlet and JSP tutorials for topics like setting up Eclipse, deploying apps, servlet basics, cookies, session tracking, JSP scripting, file inclusion, and much more. In addition, the training materials home page has tutorials on many other Java-related topics.

The PDF versions of the tutorials are freely available to anyone for personal use. These versions contain the complete text of the PowerPoint slides, and are what you want if your goal is to learn or review the technology. As a courtesy, we also make the original PowerPoint slides available to university faculty for no charge. See the J2EE instructor materials page for details.

To arrange a servlet & JSP course at your organization based on these materials, contact info@coreservlets.com. These courses can be customized to use any combination of the materials on the J2EE tutorials site, and new materials can be added for specific client needs. To learn more details about the instructor, the curriculum for the live training courses, or the public course schedule, please see http://courses.coreservlets.com.

If you find these free tutorials helpful, we would appreciate it if you would link to us.


Servlets and JSP: A Review of the Basics

Tutorial section:

Topics:

  • What servlets are all about
  • Servlet basics
  • Creating and deploying projects in Eclipse. Also see the Tomcat and Eclipse tutorial.
  • Creating forms and reading form data
  • JSP scripting
  • Using XML syntax for JSP pages
  • JSP file inclusion
  • MVC

Source code:


The Model View Controller (MVC) Architecture

Tutorial section:

Topics:

Source code:


The JSP 2 Expression Language: Simplifying MVC and Access to Java Code

Tutorial section:

Topics:

  • Motivating use of the expression language
  • Understanding the basic syntax
  • Understanding the relationship of the expression language to the MVC architecture
  • Referencing scoped variables
  • Accessing bean properties, array elements, List elements, and Map entries
  • Using expression language operators
  • Evaluating expressions conditionally
  • Comparing MVC pages: with and without the EL

Source code:


Using and Deploying Web Applications

Tutorial section:

Topics:

  • Purpose of Web applications
  • Structure of Web applications
  • Setting up Web applications with Tomcat
  • Sharing data among Web applications

Controlling Web Application Behavior: The Deployment Descriptor web.xml

Tutorial section:

Topics:

  • Location and purpose of web.xml
  • Custom URLs
  • Initialization parameters
    • Servlets
    • JSP Pages
  • Preloading pages
  • Welcome pages
  • Error pages

Declarative Web Application Security

Tutorial section:

Topics:

  • Major security concerns
  • Declarative vs. programmatic security
  • Using form-based authentication
  • Using BASIC authentication

Source code:

  • hotdotcom.zip. Web app used for the form-based security examples in this section, bundled as an Eclipse project.
  • hotdotcom-internal.zip. Web app used for the BASIC security examples in this section, bundled as an Eclipse project.
  • tomcat-users.xml. Simple Tomcat-specific username/password/role file. For real apps, always use an encrypted file: this is just for testing. Drop this file in the Tomcat "conf" folder. If you are running Tomcat manually, this is tomcat-install-dir/conf. If you are running Tomcat within Eclipse, this is something similar to eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/conf.

Programmatic Security

Tutorial section:

Topics:

  • Problems with declarative security
    • The advantages of declarative security usually outweigh the disadvantages. But not always.
  • Combination security: mixing server-managed and servlet-managed (programmatic) security
    • Solve one of the drawbacks of declarative security with only a little bit of extra work.
  • Pure programmatic security
    • Solve the other drawbacks, but with a very lot of extra work.

Source code:

  • hotdotcom-internal.zip. Web app used for the first set of examples in this section (using isUserInRole for container-managed security with some programmatic security). Bundled as an Eclipse project.
  • stocks.zip. Web app used for the second set of examples in this section (using pure programmatic security and tracing SSL info). Bundled as an Eclipse project.
  • tomcat-users.xml. Simple Tomcat-specific username/password/role file. For real apps, always use an encrypted file: this is just for testing. Drop this file in the Tomcat "conf" folder. If you are running Tomcat manually, this is tomcat-install-dir/conf. If you are running Tomcat within Eclipse, this is something similar to eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/conf. In this section, this file applies only to the hotdotcom-internal app, not the stocks app.

Servlet and JSP Filters

Tutorial section:

Topics:

  • Filter basics
  • Accessing the servlet context
  • Using initialization parameters
  • Blocking responses
  • Modifying responses
  • An abstract ModificationFilter
  • An abstract ReplaceFilter

Source code:


The Web Application Life-Cycle Events Framework

Tutorial section:

Topics:

  • Reason for listeners
  • Monitoring creation and destruction of the servlet context
  • Detecting changes in servlet context attributes
  • Recognizing session creation and destruction
  • Watching for changes in session attributes
  • Combining activities

Creating Custom JSP Tag Libraries: The Basics

Tutorial section:

Topics:

  • Java-based tags
    • Components of a tag library
    • Basic tags
    • Tags that use attributes
    • Tags that use body content
    • Tags that optionally use body content
  • JSP-based tags (tag files)
    • Components of a tag library
    • Basic tags
    • Tags that use attributes
    • Tags that use body content

Source code:


Creating Custom JSP Tag Libraries: Advanced Topics

Tutorial section:

Topics:

  • Tags with dynamic attribute values
  • Tags with complex objects for attributes
  • Manipulating the tag body
  • Looping tags
  • Nested tags
  • Using TagLibraryValidator to validate tag library syntax

Source code:


The JSP Standard Tag Library (JSTL)

Tutorial section:

Topics:

  • Obtaining JSTL documentation and code
  • The JSTL Expression Language
  • Looping Tags
  • Using JSTL to simplify Ajax data generation
  • Conditional Evaluation Tags
  • Database Access Tags
  • Other Tags

Source code:


Accessing Databases with JDBC

Tutorial section:

Topics:

  • Overview of JDBC technology
  • JDBC design strategies
  • Using Apache Derby (Java DB)
  • Seven basic steps in using JDBC
  • Using JDBC from desktop Java apps
  • Using JDBC from Web apps
  • Prepared statements (parameterized commands)
  • Meta data
  • Transaction control

Source code:


The Spring Framework: Overview and Setup

The following Spring sections are taken from the longer coreservlets.com Spring Framework tutorial.

Tutorial section:

Topics:

  • What is Spring?
    • And why use it?
  • Main Spring modules
    • Dependency injection
    • AOP
  • Configuring apps to use Spring
    • And Eclipse plugin support
  • Simple example

Source code:

  • spring-intro.zip. Sample code used in this section, bundled as an Eclipse project.
  • spring-blank.zip. Basic starting point for Spring apps: an Eclipse project with the required JAR files, a blank applicationContext.xml, the Spring IDE project nature, and nothing else. Copy and rename this when you start new Spring-based apps.

The Core Spring Module: Defining Beans and Dependency Injection

Tutorial section:

Topics:

  • Setting bean properties
  • Supplying constructor arguments
  • Using factory methods
  • Dependency injection
    • Supplying other beans as properties or constructor args
  • Bean scopes

Source code:

Using Spring in Web Apps and JSF

Tutorial section:

Topics:

  • Servlet/JSP apps
    • Creating a Dynamic Web Project in Eclipse
    • Adding Spring support
    • Adding Spring JAR files and bean definition file
    • Registering listeners in web.xml
    • Loading bean definition file
    • Getting bean instances
  • JSF apps
    • Creating a JSF Project in Eclipse
    • Adding Spring support
    • Defining beans in applicationContext.xml
    • Defining beans in faces-config.xml

Source code:

More Information

Java

Servlets & JSP
JSF
Ajax, GWT, & JavaScript

Spring, Hibernate, & JPA

Struts