WebSphere Studio Application Developer Version 5 Programming Guide part 1 ppsx

10 274 0
WebSphere Studio Application Developer Version 5 Programming Guide part 1 ppsx

Đang tải... (xem toàn văn)

Thông tin tài liệu

ibm.com/redbooks WebSphere Studio Application Developer Version 5 Programming Guide Ueli Wahli Ian Brown Fabio Ferraz Maik Schumacher Henrik Sjostrand Develop Java, Web, XML, database, EJB, and Web services applications Test with built-in and remote servers Deploy to WebSphere Application Server Front cover WebSphere Studio Application Developer Version 5 Programming Guide July 2003 International Technical Support Organization SG24-6957-00 © Copyright International Business Machines Corporation 2003. All rights reserved. Note to U.S. Government Users Restricted Rights Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. First Edition (July 2003) This edition applies to Version 5 of WebSphere Studio Application Developer and WebSphere Application Server. This book is a rewrite of the IBM Redbook, WebSphere Studio Application Developer Programming Guide , SG24-6585, which was based on Version 4 of the products. Note: Before using this information and the product it supports, read the information in “Notices” on page xix. © Copyright IBM Corp. 2003. All rights reserved. iii Contents Notices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Trademarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi The team that wrote this redbook. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii Become a published author . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii Comments welcome. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv Summary of changes from SG24-6585 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv July 2003, First Edition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv Part 1. Introducing WebSphere Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Chapter 1. Introduction and concepts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Platform architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Workbench features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Plug-in based tooling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 Role-oriented development with consistent look and feel . . . . . . . . . . . . . . . 7 Vertical and horizontal integration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Open standards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Open team development. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 File-based IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 WebSphere Studio products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 What is new in Application Developer Version 5 . . . . . . . . . . . . . . . . . . . . . . . 11 Migration from previous versions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Web development tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Relational database tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 XML tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Java development tools (JDT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Web services development tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 EJB development tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Team collaboration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Debugging tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Performance profiling tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 Server tools for testing and deployment . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Plug-in development tools. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 Sample code in this book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 iv WebSphere Studio Application Developer Version 5 Programming Guide EJBBANK database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Naming convention . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 Chapter 2. Setting up your Workbench and workspace preferences. . . . 21 Workbench basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Workspace basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Application Developer’s log files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Automatic builds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 File associations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 Local history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Perspectives preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 Internet preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Java development preferences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Java classpath variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 Appearance of Java elements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Code formatter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 Compiler options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Java Editor settings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 Installed JREs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 Javadoc documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 Organize imports. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 Refactoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Chapter 3. Perspectives, views, and editors. . . . . . . . . . . . . . . . . . . . . . . . 47 Integrated development environment (IDE) . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Application Developer help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 Perspectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Views. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 Editors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Perspective layout. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 Switching perspectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 Specifying the default perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 Organizing and customizing perspectives. . . . . . . . . . . . . . . . . . . . . . . . . . 54 Perspectives walkthrough . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 J2EE perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Resource perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 Web perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Java perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 Java Browsing perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 Contents v Java Type Hierarchy perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 Server perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 XML perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 XSL Debug perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Data perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 Debug perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Profiling perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71 Component Test perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 CVS Repository Exploring perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Install/Update perspective. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 Plug-in Development perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Chapter 4. Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 J2EE architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 Web containers and EJB containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80 EAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 WAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 JAR files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 Projects and folders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Application Developer’s project types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Simple project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Java project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 Enterprise Application project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 Web project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 EJB project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 Application Client project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Server project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85 Creating a new project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Project properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Using templates to create application projects. . . . . . . . . . . . . . . . . . . . . . . . . 88 Running the Application Template Wizard . . . . . . . . . . . . . . . . . . . . . . . . . 88 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 Part 2. Developing applications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Chapter 5. Developing Java applications . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Creating and working with a Java project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Creating a Java project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 Creating Java packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Creating Java classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Running your programs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 Exporting code and running outside Application Developer . . . . . . . . . . . 106 Locating compile errors in your code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 vi WebSphere Studio Application Developer Version 5 Programming Guide Debugging your code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Preparing a utility project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Banking model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Importing the implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Testing the model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Programming assists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Pluggable JDK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Java Scrapbook . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 Code assist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Navigating through your code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 Import generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 Tasks view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Refactoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Code generation actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 Smart compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Java search and working sets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 Bookmarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 Javadoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Preferences. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Generating Javadoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Using Ant to generate Javadoc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Chapter 6. Developing database applications . . . . . . . . . . . . . . . . . . . . . 139 JDBC overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Data source versus direct connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 Application Developer database operations. . . . . . . . . . . . . . . . . . . . . . . . . . 142 XMI and DDL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Data perspective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 DB Servers view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Data Definition view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Navigator view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 Using the DB Servers view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 Creating a database connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 Importing database objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Generate DDL and XML schema files. . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Creating database objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Create database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 Create schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Create table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Create table with foreign key. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Define the database schema in a database system . . . . . . . . . . . . . . . . . 163 Contents vii Creating SQL statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Using the SQL Statement Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Using SQL Query Builder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 Accessing databases from a Java application . . . . . . . . . . . . . . . . . . . . . . . . 174 Access using the DriverManager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 Access using a data source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 J2EE client application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 Chapter 7. Developing Web applications . . . . . . . . . . . . . . . . . . . . . . . . . 179 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 Sample application: RedBank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 Controller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 Facade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Application flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184 Creating a Web project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Adding the banking model as a utility JAR . . . . . . . . . . . . . . . . . . . . . . . . 188 Module dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Project properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Web project directory structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190 Importing existing resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 Creating static Web resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193 Create a simple HTML page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 Using the Page Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196 Using the CSS Designer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200 Creating dynamic Web resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203 Working with servlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 Working with JSPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Creating a server for testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 Testing the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225 Working with filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 Creating a filter in Application Developer . . . . . . . . . . . . . . . . . . . . . . . . . 227 Editing the filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 Working with listeners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232 Creating a listener in Application Developer . . . . . . . . . . . . . . . . . . . . . . . 233 Editing the listener. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234 Creating Web pages from a JavaBean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 Completing the code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 Tailoring the generated files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 Running the generated application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 245 viii WebSphere Studio Application Developer Version 5 Programming Guide Chapter 8. Developing Web applications with database access . . . . . . 247 Accessing databases from a Web application . . . . . . . . . . . . . . . . . . . . . . . . 248 Creating a Web project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248 Generate Web pages from SQL queries. . . . . . . . . . . . . . . . . . . . . . . . . . 249 Defining a data source in the server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256 Testing the database application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259 Accessing a database using DB Beans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260 Creating a JSP using DB Beans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 Accessing a database using JSP taglib . . . . . . . . . . . . . . . . . . . . . . . . . . 262 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270 Chapter 9. Developing applications with stored procedures . . . . . . . . . 271 What is a stored procedure? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 Creating a Java stored procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 Importing the database definition into a Web project . . . . . . . . . . . . . . . . 272 Using the Stored Procedure Wizard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273 Building the stored procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278 Executing the stored procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279 Accessing a Java stored procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 Using a main program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280 Generate a JavaBean to access the stored procedure. . . . . . . . . . . . . . . 281 Using the JSP tag library. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 Generate JavaBean Web pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 Creating a stored procedure with multiple statements . . . . . . . . . . . . . . . . . . 287 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292 Chapter 10. Developing Struts applications . . . . . . . . . . . . . . . . . . . . . . . 293 What is Struts?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 MVC architectural pattern. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294 Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 295 View . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 Controller. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296 Dependencies between MVC layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 MVC framework with Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297 Application Developer support for Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 Developing a Web application using Struts . . . . . . . . . . . . . . . . . . . . . . . . . . 301 Creating a Struts Web project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302 Copying the facade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Importing RedBank Web content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305 Updating ApplicationResources.properties . . . . . . . . . . . . . . . . . . . . . . . . 306 Creating the Struts Web diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 Implementing the Struts Web diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 Developing the form beans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310 Contents ix Developing the JSPs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 Developing the actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332 Using the Struts configuration file editor . . . . . . . . . . . . . . . . . . . . . . . . . . 336 Testing the application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344 Chapter 11. Developing XML applications . . . . . . . . . . . . . . . . . . . . . . . . 345 XML overview and technologies. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 XML and XML processor. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 DTD and XML schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 Schema and style using XSLT and XSL . . . . . . . . . . . . . . . . . . . . . . . . . . 347 XML namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 XPath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348 Application Developer XML tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 Tools demonstrated in this chapter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349 Setting up your sample project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350 Creating a new XML file from scratch . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350 Creating an XML schema . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 XML generators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 Generating a DTD from XSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 Validate XML files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 357 Generating an XML file from an XML schema . . . . . . . . . . . . . . . . . . . . . 359 Creating an XSL file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362 Transforming XML files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368 Debugging XSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369 Generating JavaBeans from DTD or XSD . . . . . . . . . . . . . . . . . . . . . . . . 371 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372 More information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372 Chapter 12. Developing EJB applications. . . . . . . . . . . . . . . . . . . . . . . . . 373 Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374 EJB server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 EJB container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 377 EJB components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379 Sample Application: RedBank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 Creating an EJB project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 386 Data transfer objects and helper classes . . . . . . . . . . . . . . . . . . . . . . . . . 388 Implementing the model with entity beans . . . . . . . . . . . . . . . . . . . . . . . . . . . 389 Creating the entity beans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389 Editing the entity beans. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 396 Creating entity relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 400 Updating the TransRecord create method . . . . . . . . . . . . . . . . . . . . . . . . 404 Creating custom finders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406 . applies to Version 5 of WebSphere Studio Application Developer and WebSphere Application Server. This book is a rewrite of the IBM Redbook, WebSphere Studio Application Developer Programming Guide ,. Web services applications Test with built-in and remote servers Deploy to WebSphere Application Server Front cover WebSphere Studio Application Developer Version 5 Programming Guide July 2003 International. . . . . 18 iv WebSphere Studio Application Developer Version 5 Programming Guide EJBBANK database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Naming

Ngày đăng: 03/07/2014, 20:20

Từ khóa liên quan

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan