Servlet and JSP Programming with IBM WebSphere Studio and









Jsp Update Database Example

and table component code does not option of databases we will retrieve data using jsp update database example. The database connection pools use git or.
jsp update database example


MVC CRUD USING JSP SERVLET AND MYSQL

You can view and download the complete source code of this tutorial from my github account. In this tutorial we will create a simple CRUD (Create Read 
MVC CRUD


Introducción a la Programación Web con Java: JSP y Servlets

este curso utilizaremos MySQL porque es gratuito. JSP en el objeto request y guardarlas en variables String. ... public static Connection con;.
Java


MySQL Connector/J 8.0 Developer Guide

For configuration examples for some J2EE application servers see Chapter 8
connector j . en.a





MySQL Connector/J 8.0 Developer Guide

For configuration examples for some J2EE application servers see Chapter 8
connector j . en


Java Server Pages Beans y JSP Tag Library Introducción

JSP directivas de página: Estructura y Creando JSP tag libraries personalizados. ... Connection con;. String url= "jdbc:mysql://localhost/agendita";.
JSP extended


Servlets & JSP - (with Tomcat & Apache)

24 ene 2001 Servlets/JSP. 1/24/2001. 8. Date Servlet/JSP Demo. Servlet. JSP ... E.g. a HTML page that contains Java code ... JSP Error Page Example ...
ServletsAndJSP OOP


Servlet and JSP Programming with IBM WebSphere Studio and

Debugging JSP generated source code . Creating additional servlet examples . ... Database Wizard JSP code is compiled within METADATA tag . . . . 290.
sg





Glassfish JAVA EE

JSP


Website Programming Based on J2EE

J2EE JSP MySQL Tomcat Servlet API HTTP HTML JDK EJB. Pages. Language function to transfer C code or building a connection between C and Java; jdb help.
Final Thesis HAN YOUJIA ?sequence= &isAllowed=y


213447 Servlet and JSP Programming with IBM WebSphere Studio and ibm.com/redbooksServlet and JSP Programmingwith IBM WebSphere Studio and VisualAge for Java

Ueli Wahli

Mitch Fielding

Gareth Mackown

Deborah Shaddon

Gert Hekkenberg

Teach yourself servlet and JSP

programming techniques

Develop and test with WebSphere

Studio and VisualAge for Java

Deploy to WebSphere

Application Server

Servlet and JSP Programming

with IBM WebSphere Studio and VisualAge for Java

May 2000

SG24-5755-00

International Technical Support Organization

© Copyright International Business Machines Corporation 2000. All rights reserved.

Note to U.S Government Users - Documentation related to restricted rights - Use, duplication or disclosure is

subject to restrictions set forth in GSA ADP Schedule Contract with IBM Corp.

First Edition (May 2000)

This edition applies to Version 3.02 of WebSphere Application Server, WebSphere Studio, and VisualAge for Java for use with the Windows NT Operating System. Many of the concepts also apply to these products running on AIX, UNIX, and OS/2 Operating Systems.

Comments may be addressed to:

IBM Corporation, International Technical Support Organization

Dept. OWR Building 80-E2

650 Harry Road

San Jose, California 95120-6099

When you send information to IBM, you grant IBM a non-exclusive right to use or distribute the

information in any way it believes appropriate without incurring any obligation to you.Before using this information and the product it supports, be sure to read the general information in

Appendix D, "Special notices" on page 429.

Take Note!

© Copyright IBM Corp. 2000iii

Contents

Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi

Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

Sample code on the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii The team that wrote this redbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxiv

Comments welcome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvi

Part 1. Web application development. . . . . . . . . . . . . . . . . . . . . . . . . . .1 Chapter 1. Environment overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 WebSphere execution environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 VisualAge for Java development environment . . . . . . . . . . . . . . . . . . . . . . . . 5 WebSphere Studio development environment . . . . . . . . . . . . . . . . . . . . . . . . 6 VisualAge for Java and WebSphere Studio interactions . . . . . . . . . . . . . . . . 7

Complete product environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Chapter 2. Product overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

How the products work together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

IBM HTTP Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

WebSphere Application Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

WebSphere Studio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

VisualAge for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Distributed Debugger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

DB2 Universal Database (UDB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

SecureWay Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

Chapter 3. Product installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Starting environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Creating a dedicated user ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Java Development Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

IBM HTTP Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Testing the install. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

DB2 Universal Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

VisualAge for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

ivServlet and JSP Programming with IBM WebSphere Studio and VisualAge for Java

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Existing errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Distributed Debugger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

WebSphere Application Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

WebSphere Studio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

SecureWay Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Incompatibilities with DB2 UDB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Configuring SecureWay Directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

What we have achieved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Chapter 4. Servlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Overview of Java servlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Servlet process flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

The Java Servlet API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

The servlet life cycle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

Basic servlet examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

Simple HTTP servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

HTML form generator servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 HTML form processing servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

Simple counter servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

Servlet initialization parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 HTTP request handling utility servlet . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Additional servlet examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

Cookie servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

URL rewriting servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

A real persistent servlet - between servlet life-cycle . . . . . . . . . . . . . . 65

User sessions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

User session counter servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

JDBC servlet. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

Servlet tag with SHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

Servlet interaction techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

Servlet collaboration: filtering and chaining. . . . . . . . . . . . . . . . . . . . . . 74 Calling servlets from servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

Response redirection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

Request dispatching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

Resource usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

Contentsv Sharing of objects in scope. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

New features of Java Servlet API 2.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

Chapter 5. JavaServer Pages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

How JavaServer Pages work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

Components of JavaServer Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

HTML tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

JSP directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

Scriptlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

WebSphere extensions to JSP scripting . . . . . . . . . . . . . . . . . . . . . . . . 103

Accessing implicit objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

Putting it all together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

JSP interactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

Invoking a JSP by URL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Calling a servlet from a JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Calling a JSP from a servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Invoking a JSP from a JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Creating dynamic content in JSPs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

Standard JSP tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

WebSphere-specific tags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

JSP utility example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

Differences between JavaServer Page specification .91 and 1.0 . . . . . . . . 122 Chapter 6. WebSphere Application Server . . . . . . . . . . . . . . . . . . . 123

WAS overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

WAS administration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126

The administrative repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 The WebSphere Administrative Console. . . . . . . . . . . . . . . . . . . . . . . . 126

WAS Topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

Node. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

Application server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

Servlet engine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

Virtual host. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

Internal servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

Creating your own Web application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Using the Task Wizard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Setting up your default error page . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138 ibm.com/redbooksServlet and JSP Programmingwith IBM WebSphere Studio and VisualAge for Java

Ueli Wahli

Mitch Fielding

Gareth Mackown

Deborah Shaddon

Gert Hekkenberg

Teach yourself servlet and JSP

programming techniques

Develop and test with WebSphere

Studio and VisualAge for Java

Deploy to WebSphere

Application Server

Servlet and JSP Programming

with IBM WebSphere Studio and VisualAge for Java

May 2000

SG24-5755-00

International Technical Support Organization

© Copyright International Business Machines Corporation 2000. All rights reserved.

Note to U.S Government Users - Documentation related to restricted rights - Use, duplication or disclosure is

subject to restrictions set forth in GSA ADP Schedule Contract with IBM Corp.

First Edition (May 2000)

This edition applies to Version 3.02 of WebSphere Application Server, WebSphere Studio, and VisualAge for Java for use with the Windows NT Operating System. Many of the concepts also apply to these products running on AIX, UNIX, and OS/2 Operating Systems.

Comments may be addressed to:

IBM Corporation, International Technical Support Organization

Dept. OWR Building 80-E2

650 Harry Road

San Jose, California 95120-6099

When you send information to IBM, you grant IBM a non-exclusive right to use or distribute the

information in any way it believes appropriate without incurring any obligation to you.Before using this information and the product it supports, be sure to read the general information in

Appendix D, "Special notices" on page 429.

Take Note!

© Copyright IBM Corp. 2000iii

Contents

Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi

Preface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii

Sample code on the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii The team that wrote this redbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxiv

Comments welcome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxvi

Part 1. Web application development. . . . . . . . . . . . . . . . . . . . . . . . . . .1 Chapter 1. Environment overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 WebSphere execution environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 VisualAge for Java development environment . . . . . . . . . . . . . . . . . . . . . . . . 5 WebSphere Studio development environment . . . . . . . . . . . . . . . . . . . . . . . . 6 VisualAge for Java and WebSphere Studio interactions . . . . . . . . . . . . . . . . 7

Complete product environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8

Chapter 2. Product overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

How the products work together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

IBM HTTP Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

WebSphere Application Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

WebSphere Studio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

VisualAge for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

Distributed Debugger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

DB2 Universal Database (UDB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

SecureWay Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

Chapter 3. Product installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Starting environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

Creating a dedicated user ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

Java Development Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

IBM HTTP Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

Testing the install. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

DB2 Universal Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

VisualAge for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

ivServlet and JSP Programming with IBM WebSphere Studio and VisualAge for Java

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Existing errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Distributed Debugger. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

WebSphere Application Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

WebSphere Studio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

SecureWay Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Incompatibilities with DB2 UDB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Configuring SecureWay Directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

What we have achieved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

Chapter 4. Servlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

Overview of Java servlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

Servlet process flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

The Java Servlet API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

The servlet life cycle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

Basic servlet examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

Simple HTTP servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

HTML form generator servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 HTML form processing servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

Simple counter servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56

Servlet initialization parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 HTTP request handling utility servlet . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Additional servlet examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

Cookie servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

URL rewriting servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

A real persistent servlet - between servlet life-cycle . . . . . . . . . . . . . . 65

User sessions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67

User session counter servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

JDBC servlet. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

Servlet tag with SHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72

Servlet interaction techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

Servlet collaboration: filtering and chaining. . . . . . . . . . . . . . . . . . . . . . 74 Calling servlets from servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

Response redirection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

Request dispatching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

Resource usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

Contentsv Sharing of objects in scope. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

New features of Java Servlet API 2.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

Chapter 5. JavaServer Pages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

How JavaServer Pages work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

Components of JavaServer Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

HTML tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

JSP directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

Scriptlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

WebSphere extensions to JSP scripting . . . . . . . . . . . . . . . . . . . . . . . . 103

Accessing implicit objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

Putting it all together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105

JSP interactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107

Invoking a JSP by URL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Calling a servlet from a JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Calling a JSP from a servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Invoking a JSP from a JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Creating dynamic content in JSPs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

Standard JSP tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

WebSphere-specific tags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

JSP utility example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122

Differences between JavaServer Page specification .91 and 1.0 . . . . . . . . 122 Chapter 6. WebSphere Application Server . . . . . . . . . . . . . . . . . . . 123

WAS overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124

WAS administration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126

The administrative repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 The WebSphere Administrative Console. . . . . . . . . . . . . . . . . . . . . . . . 126

WAS Topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

Node. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128

Application server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129

Servlet engine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130

Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131

Virtual host. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132

Internal servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134

Creating your own Web application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Using the Task Wizard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Setting up your default error page . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138