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
Ueli Wahli
Mitch Fielding
Gareth Mackown
Deborah Shaddon
Gert Hekkenberg
Teach yourself servlet and JSP
programming techniquesDevelop 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 JavaMay 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 OrganizationDept. 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 theinformation 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxivComments 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 . . . . . . . . . . . . . . . . 7Complete product environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Chapter 2. Product overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11How 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) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16SecureWay Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Chapter 3. Product installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Starting 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 JavaInstalling 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. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Configuring SecureWay Directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Testing 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53Simple counter servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Servlet initialization parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 HTTP request handling utility servlet . . . . . . . . . . . . . . . . . . . . . . . . . . 61Additional servlet examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Cookie servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
URL rewriting servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
A real persistent servlet - between servlet life-cycle . . . . . . . . . . . . . . 65User sessions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
User session counter servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68JDBC servlet. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Servlet tag with SHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72Servlet interaction techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Servlet collaboration: filtering and chaining. . . . . . . . . . . . . . . . . . . . . . 74 Calling servlets from servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Response redirection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Request dispatching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Resource usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Contentsv Sharing of objects in scope. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
New features of Java Servlet API 2.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Chapter 5. JavaServer Pages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
How JavaServer Pages work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Components of JavaServer Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98HTML tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
JSP directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Scriptlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
WebSphere extensions to JSP scripting . . . . . . . . . . . . . . . . . . . . . . . . 103Accessing 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. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111Standard JSP tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
WebSphere-specific tags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116JSP utility example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Differences between JavaServer Page specification .91 and 1.0 . . . . . . . . 122 Chapter 6. WebSphere Application Server . . . . . . . . . . . . . . . . . . . 123WAS overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
WAS administration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
The administrative repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 The WebSphere Administrative Console. . . . . . . . . . . . . . . . . . . . . . . . 126WAS 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 JavaUeli Wahli
Mitch Fielding
Gareth Mackown
Deborah Shaddon
Gert Hekkenberg
Teach yourself servlet and JSP
programming techniquesDevelop 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 JavaMay 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 OrganizationDept. 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 theinformation 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxivComments 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 . . . . . . . . . . . . . . . . 7Complete product environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Chapter 2. Product overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11How 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) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16SecureWay Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Chapter 3. Product installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Starting 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 JavaInstalling 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. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Configuring SecureWay Directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Testing 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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53Simple counter servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Servlet initialization parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 HTTP request handling utility servlet . . . . . . . . . . . . . . . . . . . . . . . . . . 61Additional servlet examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Cookie servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
URL rewriting servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
A real persistent servlet - between servlet life-cycle . . . . . . . . . . . . . . 65User sessions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
User session counter servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68JDBC servlet. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Servlet tag with SHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72Servlet interaction techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Servlet collaboration: filtering and chaining. . . . . . . . . . . . . . . . . . . . . . 74 Calling servlets from servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Response redirection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Request dispatching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Resource usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Contentsv Sharing of objects in scope. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
New features of Java Servlet API 2.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Chapter 5. JavaServer Pages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
How JavaServer Pages work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Components of JavaServer Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98HTML tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
JSP directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Scriptlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
WebSphere extensions to JSP scripting . . . . . . . . . . . . . . . . . . . . . . . . 103Accessing 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. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111Standard JSP tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
WebSphere-specific tags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116JSP utility example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Differences between JavaServer Page specification .91 and 1.0 . . . . . . . . 122 Chapter 6. WebSphere Application Server . . . . . . . . . . . . . . . . . . . 123WAS overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
WAS administration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
The administrative repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 The WebSphere Administrative Console. . . . . . . . . . . . . . . . . . . . . . . . 126WAS 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