Developing Web Applications Jbuilder 2006.pdf

(6393 KB) Pobierz
Developing Web Applications
Developing Web Applications
JBuilder ® 2005
449305054.006.png 449305054.007.png 449305054.008.png 449305054.009.png 449305054.001.png
Borland Software Corporation
100 Enterprise Way
Scotts Valley, California 95066-3249
www.borland.com
Refer to the file deploy.html located in the redist directory of your JBuilder product for a complete list
of files that you can distribute in accordance with the JBuilder License Statement and Limited
Warranty.
Borland Software Corporation may have patents and/or pending patent applications covering subject
matter in this document. Please refer to the product CD or the About dialog box for the list of
applicable patents. The furnishing of this document does not give you any license to these patents.
C OPYRIGHT © 1997–2004 Borland Software Corporation. All rights reserved. All Borland brand and
product names are trademarks or registered trademarks of Borland Software Corporation in the
United States and other countries. All other marks are the property of their respective owners.
For third-party conditions and disclaimers, see the Release Notes on your JBuilder product CD.
Printed in the U.S.A.
JB2005webapps 6E8R0804
0405060708-987654321
PDF
Contents
Chapter 1
Developing web applications 1
Documentation conventions . . . . . . . . . . . . . 2
Developer support and resources. . . . . . . . . . . 3
Contacting Borland Developer Support . . . . . . 3
Online resources. . . . . . . . . . . . . . . . . . 3
World Wide Web . . . . . . . . . . . . . . . . . . 4
Borland newsgroups . . . . . . . . . . . . . . . . 4
Usenet newsgroups . . . . . . . . . . . . . . . . 4
Reporting bugs . . . . . . . . . . . . . . . . . . 4
Content page . . . . . . . . . . . . . . . . . 29
Obfuscation page . . . . . . . . . . . . . . . 32
Deployment page . . . . . . . . . . . . . . . 32
Refactoring page . . . . . . . . . . . . . . . 33
Signature page . . . . . . . . . . . . . . . . 33
WAR files . . . . . . . . . . . . . . . . . . . . . . 34
Applets in a WAR file . . . . . . . . . . . . . . . 35
Chapter 5
Working with web applications
in the JBuilder IDE 37
Creating a runtime configuration. . . . . . . . . . . 38
Creating a runtime configuration
with the wizards . . . . . . . . . . . . . . . . . 38
Creating an applet runtime configuration . . . . . 39
Creating a server runtime configuration . . . . . 40
How URLs run servlets . . . . . . . . . . . . 44
Setting run properties . . . . . . . . . . . . . . . . 46
Configuring the IDE for web run/debug . . . . . . . 47
Compiling your servlet or JSP . . . . . . . . . . . . 48
Web running your servlet or JSP . . . . . . . . . . 48
Starting your web server . . . . . . . . . . . . . 49
Web view . . . . . . . . . . . . . . . . . . . 49
Web view source . . . . . . . . . . . . . . . 50
Stopping the web server . . . . . . . . . . . . . 50
Web debugging your servlet or JSP . . . . . . . . . 51
Part I
Working with web applications
Chapter 2
Introduction
9
Chapter 3
Overview of the web application
development process 11
Servlets . . . . . . . . . . . . . . . . . . . . . . . . 12
JavaServer Pages (JSP) . . . . . . . . . . . . . . . 13
JavaServer Faces (JSF) . . . . . . . . . . . . . . . 14
Struts . . . . . . . . . . . . . . . . . . . . . . . . . 14
JavaServer Pages Standard Tag Library (JSTL) . . . 15
InternetBeans Express . . . . . . . . . . . . . . . . 15
Applets . . . . . . . . . . . . . . . . . . . . . . . . 15
Java Web Start . . . . . . . . . . . . . . . . . . . . 16
Deciding which technologies to use in
your web application. . . . . . . . . . . . . . . . . 16
The basic web application development process . . . 17
Web applications vs. distributed applications . . . . . 18
Chapter 6
Using the TCP Monitor 53
Enabling the TCP Monitor . . . . . . . . . . . . . . 54
Configuring the server port . . . . . . . . . . . . . 55
Running the TCP Monitor . . . . . . . . . . . . . . 56
Resending a packet . . . . . . . . . . . . . . . . . 57
Disabling the TCP Monitor . . . . . . . . . . . . . . 57
The TCP Monitor UI . . . . . . . . . . . . . . . . . 57
Chapter 4
Working with web modules
and WAR files 19
Web modules . . . . . . . . . . . . . . . . . . . . . 19
Web archive (WAR) files . . . . . . . . . . . . . . . 20
Tools for working with web modules
and WAR files . . . . . . . . . . . . . . . . . . . . 20
Creating a web module with the
Web Module wizard . . . . . . . . . . . . . . . . . 21
The web module . . . . . . . . . . . . . . . . . . . 23
Module directory . . . . . . . . . . . . . . . . . . 24
Deployment descriptors . . . . . . . . . . . . . . 25
Web module properties . . . . . . . . . . . . . . 26
Module page . . . . . . . . . . . . . . . . . . 26
Web page. . . . . . . . . . . . . . . . . . . . 27
Clean page . . . . . . . . . . . . . . . . . . . 28
Build page . . . . . . . . . . . . . . . . . . . 28
Chapter 7
Deploying your web application 59
Overview . . . . . . . . . . . . . . . . . . . . . . . 59
Archive files. . . . . . . . . . . . . . . . . . . . 59
Deployment descriptors . . . . . . . . . . . . . 60
Applets . . . . . . . . . . . . . . . . . . . . . . 60
Servlets . . . . . . . . . . . . . . . . . . . . . . 60
JSPs . . . . . . . . . . . . . . . . . . . . . . . 60
Testing your web application . . . . . . . . . . . 61
Editing deployment descriptors . . . . . . . . . . . 61
Deployment descriptor refactoring . . . . . . . . 62
Editing vendor-specific deployment
descriptors . . . . . . . . . . . . . . . . . . . 62
More information on deployment descriptors . . . 62
i
449305054.002.png 449305054.003.png
Chapter 8
Editing the web.xml file 63
Web Module DD editor types of pages . . . . . . . . 64
Web Module DD editor context menu . . . . . . . . 64
Web Application page . . . . . . . . . . . . . . . . 64
Context Parameters page . . . . . . . . . . . . . . 65
EJB References page . . . . . . . . . . . . . . . . 65
EJB Local References page . . . . . . . . . . . . . 65
Environment Entries page . . . . . . . . . . . . . . 65
Error Pages page . . . . . . . . . . . . . . . . . . . 66
Filters page . . . . . . . . . . . . . . . . . . . . . . 66
Initialization Parameters . . . . . . . . . . . . . . 66
Filter Mappings page . . . . . . . . . . . . . . . . . 67
JSP Property Groups page . . . . . . . . . . . . . . 67
Listeners page . . . . . . . . . . . . . . . . . . . . 67
Locale Encoding Mapping Lists page . . . . . . . . 67
Message Destinations page . . . . . . . . . . . . . 68
Message Destination References page . . . . . . . 68
MIME Mappings page . . . . . . . . . . . . . . . . 68
Resource Environment References page . . . . . . 69
Resource References page . . . . . . . . . . . . . 69
Security Constraints page . . . . . . . . . . . . . . 69
Web Resource Collections page . . . . . . . . . 70
Servlets page . . . . . . . . . . . . . . . . . . . . . 70
Initialization Parameters . . . . . . . . . . . . . . 70
Security Role References . . . . . . . . . . . . . 71
Servlet Mappings page . . . . . . . . . . . . . . . . 71
Security Roles page . . . . . . . . . . . . . . . . . 71
Service References page. . . . . . . . . . . . . . . 72
Port Component References page . . . . . . . . 72
Handlers page . . . . . . . . . . . . . . . . . . . 72
Initialization Parameters . . . . . . . . . . . . 72
Tag Libraries page . . . . . . . . . . . . . . . . . . 73
Welcome File Lists page . . . . . . . . . . . . . . . 73
Using third-party libraries . . . . . . . . . . . . . . .83
Deploying applets . . . . . . . . . . . . . . . . . . .83
Testing applets . . . . . . . . . . . . . . . . . . . .84
Basic testing steps . . . . . . . . . . . . . . . . .84
Testing in the browsers. . . . . . . . . . . . . . .85
JBuilder and applets. . . . . . . . . . . . . . . . . .85
Creating applets with the Applet wizard . . . . . .85
Running applets . . . . . . . . . . . . . . . . . .87
JBuilder’s AppletTestbed and
Sun’s appletviewer . . . . . . . . . . . . . .87
Running JDK 1.1.x applets in JBuilder . . . . .88
Running JDK 1.2 applets in JBuilder . . . . . .88
Debugging applets . . . . . . . . . . . . . . . . .88
Debugging applets in the Java Plug-in . . . . .89
Deploying applets in JBuilder . . . . . . . . . . .89
Chapter 10
Launching your web application
with Java Web Start 91
Considerations for Java Web Start applications. . . .91
Installing Java Web Start . . . . . . . . . . . . . . .92
Java Web Start and JDK 5.0 . . . . . . . . . . . .93
Java Web Start and JBuilder . . . . . . . . . . . . .93
The application’s JAR file . . . . . . . . . . . . .95
The application’s JNLP file and homepage . . . .95
Chapter 11
Web application hints and tips 97
Creating a JSP in a web module subdirectory . . . .97
Creating JSPs with identical names . . . . . . . . . .97
Specifying a directory for a servlet
generated from a JSP . . . . . . . . . . . . . . . .98
Changing the web server’s port number . . . . . . .98
Adding a server-specific XML file to
the WAR file . . . . . . . . . . . . . . . . . . . . .98
Adding additional file types to your web module
and including them in the WAR file . . . . . . . . .99
Viewing contents of WEB-INF directory . . . . . . . .99
Disabling automatic generation
of the WAR file . . . . . . . . . . . . . . . . . . . .99
Testing a web application in an
external browser . . . . . . . . . . . . . . . . . . 100
Opening the JSF Flow designer . . . . . . . . . . . 100
Opening the JSF Navigation designer. . . . . . . . 100
Opening a Struts designer . . . . . . . . . . . . . 101
Opening the Tiles designer . . . . . . . . . . . . . 101
Creating a tiles-def.xml file . . . . . . . . . . . . . 101
Creating a validation.xml file . . . . . . . . . . . . 101
Adding and registering deployment descriptors . . . 101
Importing an existing web module. . . . . . . . . . 102
Creating a web module from an
existing archive . . . . . . . . . . . . . . . . . . 102
Debugging HTTP requests and responses . . . . . 103
Chapter 9
Working with applets 75
How do applets work? . . . . . . . . . . . . . . . . 75
The <applet> tag . . . . . . . . . . . . . . . . . . . 76
Sample <applet> tag . . . . . . . . . . . . . . . 76
<applet> tag attributes. . . . . . . . . . . . . . . 76
Common mistakes in the <applet> tag . . . . . . 77
Browser issues . . . . . . . . . . . . . . . . . . . . 78
Java support. . . . . . . . . . . . . . . . . . . . 78
Getting the preferred browser to
the end user . . . . . . . . . . . . . . . . . . . 78
Supporting multiple browsers . . . . . . . . . . . 78
Differences in Java implementation . . . . . . . . 78
Solutions to browser issues . . . . . . . . . . . . 79
Additional tips for making applets work. . . . . . . . 80
Security and the security manager . . . . . . . . . . 81
The sandbox. . . . . . . . . . . . . . . . . . . . 81
Applet restrictions . . . . . . . . . . . . . . . . . 82
Solutions to security problems . . . . . . . . . . 82
ii
Part II
Developing JavaServer Pages
and servlets
Chapter 15
Using InternetBeans Express 137
Overview of InternetBeans Express classes . . . . 138
Using InternetBeans Express with servlets . . . . . 139
Posting data with servlets using
InternetBeans Express . . . . . . . . . . . . . 139
Parsing pages . . . . . . . . . . . . . . . . . . 139
Generating tables. . . . . . . . . . . . . . . . . 140
Using InternetBeans Express with JSPs . . . . . . 140
Table of InternetBeans tags . . . . . . . . . . . 141
Format of internetbeans.tld . . . . . . . . . . . . 142
Chapter 12
Introduction
107
Chapter 13
Developing JavaServer Pages 109
JSP tags . . . . . . . . . . . . . . . . . . . . . . 110
JSP tag libraries and frameworks . . . . . . . . . . 111
JSPs in JBuilder . . . . . . . . . . . . . . . . . . 112
Working with JSP tag libraries and
frameworks in JBuilder . . . . . . . . . . . . . 112
Using the Configure Libraries dialog box
to manage user-defined frameworks . . . . 113
Developing a JSP . . . . . . . . . . . . . . . . 115
The JSP wizard . . . . . . . . . . . . . . . . 115
Compiling a JSP . . . . . . . . . . . . . . . . . 117
Web running a JSP . . . . . . . . . . . . . . . 118
Debugging JSPs . . . . . . . . . . . . . . . . . 118
Stepping into included JSP files . . . . . . . 119
Runtime configuration option
for JSP debugging . . . . . . . . . . . . . 119
Your project’s Tomcat work directory . . . . . 119
Smart Swap and JSP debugging . . . . . . . 119
Debugging JSPs in subdirectories . . . . . . 120
Debugging JSPs with identical names . . . . 120
Remote JSP debugging . . . . . . . . . . . 120
Deploying a JSP . . . . . . . . . . . . . . . . . 120
Additional JSP resources . . . . . . . . . . . . . . 120
Part III
Developing JavaServer Faces web
applications
Chapter 16
Introduction
147
Chapter 17
Using the JSF framework inJBuilder 149
JBuilder tools for JSF . . . . . . . . . . . . . . . . 150
JSF project pane display . . . . . . . . . . . . . 150
Adding JSF deployment descriptors
to your web module . . . . . . . . . . . . . . . 150
Registering JSF deployment descriptors . . . . . 150
JSF framework support. . . . . . . . . . . . . . 152
Web Module wizard. . . . . . . . . . . . . . . . 152
JSP wizard . . . . . . . . . . . . . . . . . . . . 153
JSF page editor. . . . . . . . . . . . . . . . . . 153
Structure pane. . . . . . . . . . . . . . . . . 153
Page editor . . . . . . . . . . . . . . . . . . 154
Tag component palette . . . . . . . . . . . . 154
Tag inspector . . . . . . . . . . . . . . . . . 154
Faces Config editor . . . . . . . . . . . . . . . . 154
JSF designers . . . . . . . . . . . . . . . . . . 155
Creating a JSF-enabled web application . . . . . . 155
Chapter 14
Developing servlets 123
Servlets and JSPs . . . . . . . . . . . . . . . . . 124
Servlets and web servers . . . . . . . . . . . . . . 125
The servlet API . . . . . . . . . . . . . . . . . . . 125
The servlet.HTTP package . . . . . . . . . . . 125
The servlet lifecycle . . . . . . . . . . . . . . . . . 126
Constructing and initializing the servlet . . . . . 126
Handling client requests . . . . . . . . . . . . . 126
Servlets and multi-threading . . . . . . . . . . . 126
Destroying a servlet . . . . . . . . . . . . . . . 126
Servlet-aware HTML . . . . . . . . . . . . . . . . 127
HTTP-specific servlets . . . . . . . . . . . . . . . 127
Creating a servlet with the Servlet wizard . . . . . 127
Creating a standard servlet . . . . . . . . . . . 128
Creating a filter servlet. . . . . . . . . . . . . . 131
Creating a listener servlet . . . . . . . . . . . . 132
Compiling a servlet . . . . . . . . . . . . . . . . . 133
Web running a servlet. . . . . . . . . . . . . . . . 133
Invoking a servlet from a web browser . . . . . 133
Calling a servlet from an HTML page . . . . . . 134
Debugging servlets . . . . . . . . . . . . . . . . . 134
Deploying servlets . . . . . . . . . . . . . . . . . 135
Internationalizing servlets . . . . . . . . . . . . . . 135
Writing a data-aware servlet . . . . . . . . . . . . 135
Chapter 18
Editing the faces-config.xml file 157
The Faces Config editor . . . . . . . . . . . . . . . 157
Structure pane . . . . . . . . . . . . . . . . . . 158
Faces Config editor types of pages. . . . . . . . 158
The Faces Config editor context menu . . . . . . 159
Application Configuration category . . . . . . . . . 159
Application page . . . . . . . . . . . . . . . . . 159
Locale Configuration page . . . . . . . . . . . . 159
Lifecycle page . . . . . . . . . . . . . . . . . . 159
Factories page . . . . . . . . . . . . . . . . . . 160
Application Development category . . . . . . . . . 160
Navigation Rules page . . . . . . . . . . . . . . 160
Navigation Case page . . . . . . . . . . . . . 160
Managed Beans page . . . . . . . . . . . . . . 161
Managed Property page . . . . . . . . . . . 161
Referenced Beans page . . . . . . . . . . . . . 161
Converters page . . . . . . . . . . . . . . . . . 162
Attribute page . . . . . . . . . . . . . . . . . 162
Property page . . . . . . . . . . . . . . . . . 163
iii
449305054.004.png 449305054.005.png
Zgłoś jeśli naruszono regulamin