CIS 5930-04 – Spring 2001

1/8/2001


Click here to start


Table of Contents

CIS 5930-04 – Spring 2001

Introduction

HTML Forms and CGI

CGI and Servlets

Advantages of Servlets

Plan of this Lecture Set

References

HTML Forms

The HTTP GET request

A Dummy Web Server

A GET Request

Fields of the GET request

A Simple HTML Form

Remarks

Displaying the Form

Submitting the Form

Remarks

POST requests

A Form Using the POST Method

Extending the Dummy Server

Submitting the Form

Remarks

URL Encoding

More Options for the input Tag

Radio Buttons

Checkboxes

Checkboxes

File-Selection

File-Selection Entry

Output of DummyServer on submit

Remarks

Masked and Hidden fields

Text Areas

Text Area Input

Scrollable Menus (Lists)

List Input

Conventional CGI

Handling Form Data on the Server

Operation of a CGI Script

“Hello World” CGI Script

Output from CGI Script

Retrieving Form Data

GET example

POST example

Using the CGI module

CGI module example

Getting Started with Servlets

Server Software

Tomcat

Typical Modes of Operation of Tomcat

Downloading Tomcat

Unpacking and Setting the Environment

Servers on Course Hosts: Ground Rules

Choosing a Port

Removing the AJP Connector

Starting and Stopping your Server

Check Your Server is Running

First Servlets

Creating a Context

Creating a Document Directory

A Directory for Servlet Classes

A “Hello World” Servlet

Remarks

Setting the Class Path

Compiling and Deploying the Servlet

A Servlet that Reads a Parameter

First Form using a Servlet

The Servlet Life Cycle

Servlet Classes

Servlet Instances

The init() Method

The Request Handling Methods

Last Modification Date

The destroy() method.

A Counter Servlet

Remarks

Mutual Exclusion

Registering Servlet Instances

Example Registering a Servlet

Multiple Instances

Initialization Parameters

Defining Initialization Parameters

Handling Requests

Reading Form Data

Uniform support for GET and POST

Determining the HTTP Method

Information from Request Headers

Reading Request Headers Directly

Displaying All Headers

HTTP 1.1 Request Headers

HTTP 1.1 Request Headers (cont.)

Multiple-valued Parameters

Handling Multi-valued Parameters

Multi-part Data

Displaying Raw Multi-part Data

Remarks

Multi-part Data Example

Multi-part Data Example (cont.)

Remarks

Generating Responses

The HTTP Status Line

HTTP Status Codes

HTTP Status Codes (cont.)

HTTP Status Codes (cont.)

Explicitly Returning Status Codes

Redirecting the Browser

Search-Engine Selection Servlet

Remarks

Introduction to Session Tracking

The Problem

Solutions

Example Using Hidden Form Fields

Snack-Vending Machine

Remarks

The Initial Page

Generated Source of Initial Page

Making Selections

Generated Source of Later Pages

Handling the Accumulated “State”

Critique of Hidden Fields

Session IDs

Improved Vending Machine Servlet

A Second Vending Machine

Remarks

Server Restarts

URL-Rewriting

A Third Vending Machine

Remarks

Cookies

Cookies

Uses of Cookies

Abuses of Cookies

Limits to Cookies

The Servlet Cookie API

A Servlet that Sets Two Cookies

Remarks

Viewing the Set-Cookie Headers

HTTP Response Including Set-Cookie

Browser Behavior

Retrieving Cookies with the Cookie API

Displaying Cookies

Remarks

Visiting ShowCookies

Session Tracking Using Cookies

A Fourth Vending Machine

Remarks

The Servlet Session Tracking API

The Session Tracking API

The HttpSession class

Simple Example

Remarks

Viewing the Generated Page

Checking the Cookies

Revisiting the Servlet

Selecting a Session Tracking Mechanism

Binding Information to a Session

Some Methods on HttpSession

Session Attributes vs. Instance Variables

A Final (?) Vending Machine

A Fifth Vending Machine

Remarks

The Scope of a Session

Life-Time of a Session

Author: Bryan Carpenter

Email: dbc@csit.fsu.edu

Home Page: http://aspen.csit.fsu.edu/it1spring01