With IBM WebSphere Studio And VisualAge For Java

Transcription

Servlet and JSPProgrammingwith IBM WebSphere Studio and VisualAge for JavaTeach yourself servlet and JSPprogramming techniquesDevelop and test with WebSphereStudio and VisualAge for JavaDeploy to WebSphereApplication ServerUeli WahliMitch FieldingGareth MackownDeborah ShaddonGert Hekkenbergibm.com/redbooks

SG24-5755-00International Technical Support OrganizationServlet and JSP Programmingwith IBM WebSphere Studioand VisualAge for JavaMay 2000

Take Note!Before using this information and the product it supports, be sure to read the general information inAppendix D, “Special notices” on page 429.First Edition (May 2000)This edition applies to Version 3.02 of WebSphere Application Server, WebSphere Studio, andVisualAge for Java for use with the Windows NT Operating System. Many of the concepts also apply tothese products running on AIX, UNIX, and OS/2 Operating Systems.Comments may be addressed to:IBM Corporation, International Technical Support OrganizationDept. OWR Building 80-E2650 Harry RoadSan Jose, California 95120-6099When 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. Copyright International Business Machines Corporation 2000. All rights reserved.Note to U.S Government Users – Documentation related to restricted rights – Use, duplication or disclosure issubject to restrictions set forth in GSA ADP Schedule Contract with IBM Corp.

ContentsFigures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiiiTables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiPreface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiiiSample code on the Internet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiiiThe team that wrote this redbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxivComments welcome . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .xxviPart 1. Web application development . . . . . . . . . . . . . . . . . . . . . . . . . . .1Chapter 1. Environment overview. . . . . . . . . . . . .WebSphere execution environment . . . . . . . . . . . . . . . . .VisualAge for Java development environment . . . . . . . .WebSphere Studio development environment . . . . . . . .VisualAge for Java and WebSphere Studio interactionsComplete product environment . . . . . . . . . . . . . . . . . . . .345678Chapter 2. Product overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11How the products work together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11IBM HTTP Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12WebSphere Application Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12WebSphere Studio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14VisualAge for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15Distributed Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16DB2 Universal Database (UDB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16SecureWay Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16Chapter 3. Product installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Starting environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17Creating a dedicated user ID . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18Java Development Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18IBM HTTP Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19Testing the install. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19DB2 Universal Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22VisualAge for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Copyright IBM Corp. 2000iii

Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Existing errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Distributed Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26WebSphere Application Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30WebSphere Studio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34SecureWay Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Incompatibilities with DB2 UDB. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Installing the product. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Configuring SecureWay Directory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Testing the installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40What we have achieved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40Chapter 4. Servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41Overview of Java servlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42Servlet process flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42The Java Servlet API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43The servlet life cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Basic servlet examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Simple HTTP servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47HTML form generator servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51HTML form processing servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53Simple counter servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56Servlet initialization parameters. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58HTTP request handling utility servlet . . . . . . . . . . . . . . . . . . . . . . . . . . 61Additional servlet examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62Cookie servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62URL rewriting servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64A real persistent servlet — between servlet life-cycle . . . . . . . . . . . . . . 65User sessions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67User session counter servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68JDBC servlet. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70Servlet tag with SHTML . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72Servlet interaction techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73Servlet collaboration: filtering and chaining. . . . . . . . . . . . . . . . . . . . . . 74Calling servlets from servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Response redirection. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Request dispatching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81Resource usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84ivServlet and JSP Programming with IBM WebSphere Studio and VisualAge for Java

Sharing of objects in scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86New features of Java Servlet API 2.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94Chapter 5. JavaServer Pages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96How JavaServer Pages work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97Components of JavaServer Pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98HTML tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99JSP directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101Scriptlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102WebSphere extensions to JSP scripting . . . . . . . . . . . . . . . . . . . . . . . . 103Accessing implicit objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104Putting it all together. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105JSP interactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107Invoking a JSP by URL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107Calling a servlet from a JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107Calling a JSP from a servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109Invoking a JSP from a JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111Creating dynamic content in JSPs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111Standard JSP tags . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111WebSphere-specific tags. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116JSP utility example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122Differences between JavaServer Page specification .91 and 1.0 . . . . . . . . 122Chapter 6. WebSphere Application Server . . . . . . . . . . . . . . . . . . . 123WAS overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124WAS administration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126The administrative repository . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126The WebSphere Administrative Console. . . . . . . . . . . . . . . . . . . . . . . . 126WAS Topology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128Node. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128Application server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129Servlet engine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131Virtual host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132Internal servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134Creating your own Web application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135Using the Task Wizard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135Setting up your default error page . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138Contentsv

Creating the required Web application directories. . . . . . . . . . . . . . . . 139Deploying files to WAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140Defining servlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140Start the Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141Class loading and reloading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Changing the application server class path . . . . . . . . . . . . . . . . . . . . . 142Using JNI in WAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143Creating an application server environment variable . . . . . . . . . . . . . 143Setting up connection pools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145Creating a JDBC driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145Creating a DataSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146Migrating from the connection manager. . . . . . . . . . . . . . . . . . . . . . . . 146Using JavaServer Pages in WAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Adding JSP support to a Web application. . . . . . . . . . . . . . . . . . . . . . . 147Keeping Java source files from JSP 1.0 compilation . . . . . . . . . . . . . . 148Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149How security works in WAS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149Configuring an enterprise application. . . . . . . . . . . . . . . . . . . . . . . . . . 150Setting up security in WAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152XML configuration interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162Exporting configuration data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162Importing configuration data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163Examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163User profiling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164Troubleshooting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164Tracing within WAS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165Monitoring resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166Reference information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166Chapter 7. Development and testing with VisualAge for Java . 167VisualAge for Java overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168Application development with VisualAge for Java . . . . . . . . . . . . . . . . . . . 170Rapid application development (RAD) . . . . . . . . . . . . . . . . . . . . . . . . . 170Create industrial-strength Java applications . . . . . . . . . . . . . . . . . . . . 171Maintain multiple editions of programs . . . . . . . . . . . . . . . . . . . . . . . . 171VisualAge for Java components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171Navigating in VisualAge for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Additional VisualAge for Java concepts . . . . . . . . . . . . . . . . . . . . . . . . 181Servlet development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185Rapid servlet development. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185The development process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186Developing our first servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187WebSphere Test Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191viServlet and JSP Programming with IBM WebSphere Studio and VisualAge for Java

VisualAge for Java configuration for WebSphere. . . . . . . . . . . . . . . . . 192WebSphere Test Environment setup. . . . . . . . . . . . . . . . . . . . . . . . . . . 192Start the WebSphere Test Environment. . . . . . . . . . . . . . . . . . . . . . . . 192What have we accomplished?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196Testing JSPs under WebSphere Test Environment . . . . . . . . . . . . . . . . . . 197VisualAge for Java configuration for JSPs . . . . . . . . . . . . . . . . . . . . . . 197Configuring the JSP version used by VisualAge for Java . . . . . . . . . . 197Running our first JSP. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198Creating and running a JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200Debugging servlets and JSPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201Debugger basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201Debugging a servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203JSP Execution Monitor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206Debugging JSP generated source code . . . . . . . . . . . . . . . . . . . . . . . . . 208WebSphere Test Environment — advanced configuration. . . . . . . . . . . . . 208Types of resources. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209Additional servlet examples. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209Resource locations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209The four key configuration files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210Configuration for servlet chaining, filtering, and SHTML. . . . . . . . . . 212Developing and testing additional servlet and JSP configurations . . . . . . 214Creating additional servlet examples . . . . . . . . . . . . . . . . . . . . . . . . . . 214WebSphere Test Environment — multiple Web applications . . . . . . . . . . 215Configuring multiple Web applications. . . . . . . . . . . . . . . . . . . . . . . . . 215Configuring the ServletEngine class . . . . . . . . . . . . . . . . . . . . . . . . . . . 217Launching ServletEngine. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219Using the ServletEngineConfigDumper servlet . . . . . . . . . . . . . . . . . . 220Restoring SERunner. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221Configuring and testing servlet and JSP interactions . . . . . . . . . . . . . . . . 222Support for JavaBeans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222Team development . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223Resource management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225Chapter 8. Development with WebSphere Studio . . . . . . . . . . . . . 227WebSphere Studio overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228The WebSphere Studio IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230Creating a project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230Setting the JSP version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232Setting up folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233Adding files to the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234Setting the file status . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236Editing project resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237Contentsvii

Checking-out and checking-in files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237Invoking Page Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238Using forms and input fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239Calling a servlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241Preview the form and view HTML source. . . . . . . . . . . . . . . . . . . . . . . 242Inserting a JavaBean into a JSP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244Modifying JavaBeans and servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246Compiling source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247Publishing stages and publishing targets . . . . . . . . . . . . . . . . . . . . . . . . . . 247Setting up the Test stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248Setting up the Production stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250Publishing to a Web application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251Project relationships and integrity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253Publishing a project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255Testing published files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256WebSphere Studio wizards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257Code produced by the wizards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257SQL Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258Run the SQL Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258Changing the SQL statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264Database Wizard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265Run the Database Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265Database Wizard generated code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270Run the generated application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272Enhance the application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273JavaBean Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276Run the JavaBean Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276Test the JavaBean Wizard code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280JavaBean Wizard — what for? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280Developing an application in WebSphere Studio . . . . . . . . . . . . . . . . . . . . 281Create the SQL statement for the employees of a department . . . . . . 281Create the SQL statement for the employee photo. . . . . . . . . . . . . . . . 282Generate the code for the employees in a department . . . . . . . . . . . . . 283Generate the code for the employee photo . . . . . . . . . . . . . . . . . . . . . . 283Change the generated DataSource . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283Fixing the problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284Testing in VisualAge for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284Displaying a picture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285Linking the servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286Run the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 288Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289Resolving parsing problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289Folders in publishing stages for a Web application . . . . . . . . . . . . . . . 290viiiServlet and JSP Programming with IBM WebSphere Studio and VisualAge for Java

SQL Wizard generates wrong data type for a BLOB column . . . . . . . 290Database Wizard JSP code is compiled within METADATA tag . . . . 290JavaBean Wizard generates bad code . . . . . . . . . . . . . . . . . . . . . . . . . . 290Interfacing to VisualAge for Java . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291Setting up the environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 291WebSphere Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292Receiving updates from Visual Age for Java. . . . . . . . . . . . . . . . . . . . . 292Sending updates to Visual Age for Java . . . . . . . . . . . . . . . . . . . . . . . . 293Using VisualAge for Java as an editor . . . . . . . . . . . . . . . . . . . . . . . . . 293Archiving . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293Opening an archive. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293Working in a team . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294More information and examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294Chapter 9. Software Configuration Management . . . . . . . . . . . . . 295Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296What is Software Configuration Management? . . . . . . . . . . . . . . . . . . 296SCM for architectural pattern based development. . . . . . . . . . . . . . . . . . . 298Developer roles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299Implementing SCM aspects in a WebSphere Studio environment . . . . . . 302SCM aspects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302Choice for Clearcase as physical single point of control . . . . . . . . . . . . 306Rational SCM toolset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306ClearCase . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306ClearQuest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307Unified Change Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307Our approach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308ClearCase in the WebSphere Studio environment . . . . . . . . . . . . . . . . . . . 309Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309WebSphere Studio and ClearCase considerations . . . . . . . . . . . . . . . . 312Setting up a ClearCase project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313Create the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315Create a view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320Enable ClearCase to the WebSphere Studio environment. . . . . . . . . . 322Bring the projects artifacts under ClearCase control. . . . . . . . . . . . . . 323Working from WebSphere Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325Reflections on SCM procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327WebSphere Studio and ClearCase in the broader SCM context . . . . . 328Rational Rose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328Epilog. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330Chapter 10. Web application design with servlets and JSPs. . . 331Application structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331Contentsix

HTML page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333Servlet . . . . . . . . . . . . . . . . . . . . . . . . . .

with 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.