Home > Store

Special Edition Using Java Server Pages and Servlets

Register your product to gain access to bonus material or receive a coupon.

Special Edition Using Java Server Pages and Servlets

eBook (Adobe DRM)

  • Sorry, this book is no longer in print.
  • About Adobe DRM eBooks
  • This eBook requires the free Adobe® Digital Editions software.

    Before downloading this DRM-encrypted PDF, be sure to:


    • Install the free Adobe Digital Editions software on your machine. Adobe Digital Editions only works on Macintosh and Windows, and requires the Adobe Flash Player. Please see the official system requirements.
    • Authorize your copy of Adobe Digital Editions using your Adobe ID (select AdobeID as the eBook vendor). If you don't already have an Adobe ID, you can create one here.
Not for Sale

Description

  • Copyright 2003
  • Pages: 768
  • Edition: 1st
  • eBook (Adobe DRM)
  • ISBN-10: 0-7686-5605-2
  • ISBN-13: 978-0-7686-5605-3

Special Edition Using JSP and Servlets starts by detailing the evolution of web servers that led to the creation of ASP and JSP. It explains both the limitations of previous technologies and the benefits that JSP provides including platform independence. Includes coverage of: organizing applications with multiple files and client-side objects, generating well-formed XML using JSP, storing data in cookies and sessions, interacting with Enterprise Java Beans, displaying dynamic graphics with Java 2D, and using RMI and Corba to enhance JSP applications. The final chapters demonstrate advanced JSP & Servlet techniques, including using JSP to create wireless & XML-based applications. Appendices provide an overview of popular JSP & Servlet runtime environments, including Jrun, Tomcat and ServletExec.

Sample Content

Table of Contents



Introduction.

Who Should Buy This Book. How This Book Is Organized. Conventions Used in This Book.

I. BASIC JAVA SERVER PAGES.

1. The Evolution of the Web Server.

The Basic Web Server. CGI: The Common Gateway Interface. NSAPI, ISAPI, and Other Loadable Modules. Active Server Pages. Servlets. XML and XSL Stylesheets. Java Server Pages.

2. Getting Started with Java Server Pages.

A “Hello World” Java Server Page. Using the % % Tags in a Java Server Page. Displaying a Value with %=. Inserting Comments. Declaring Methods and Variables with %!. Handling Multiple Threads in a JSP. Troubleshooting.

3. Getting Started with Servlets.

A "Hello World" Servlet.

Compiling the Servlet. Runtime Classpath. The HelloWorldServlet In-Depth.

The Anatomy of a Servlet.

The <F102MO>service Method. The init Method. The destroy Method. The getServletInfo and getServletConfig Methods.

Sending a Response to the Browser. The <F102MO>HttpServlet Class. Choosing Between Java Server Pages and Servlets.

The Advantages and Disadvantages of JSP. The Advantages and Disadvantages of Servlets.

Troubleshooting.

4. Creating HTML Forms.

A Simple HTML Form. Using the request Object.

Handling Multiple Form Values.

Retrieving Form Variables in a Servlet. JavaScript and Java Server Pages.

Passing Data to JavaScript.

Different Ways to Do Forms.

A Practical HTML and JSP Combination. Setting Configuration Parameters. Locking Output Files.

A JSP Input Form Calling a JSP Form Handler. Using the Same JSP for the Input Form and Form Handler.

An Example Input Form and Form Handler JSP.

Troubleshooting.

5. Saving Data Between Requests.

Storing Data in Hidden Form Variables.

Security Concerns with Hidden Variables.

Storing Data in a session Object.

Using the session Object in a JSP. Using the <F102MO>session Object in a Servlet.

How Sessions Work. Forcing a New Session. Handling Session Termination.

The HttpSessionBindingListener Interface.

Handling Sessions Without Cookies.

Disabling Cookies in Internet Explorer. Disabling Cookies in Netscape.

Storing Application-Wide Data.

Why Do You Need the application Object?

Troubleshooting.

6. Debugging and Error Handling.

Why Debugging Is Tough. Using Log Files to Debug an Application.

Using System.out and System.err. Using the Servlet Logging API. Logging to a File. Using Exceptions to Trace Execution.

Using a Debugger.

Debugging a Servlet with Tomcat. Debugging a Java Server Page with Tomcat.

Error Handling.

Specifying an Error Page for a JSP. Specifying Error Handlers for Web Server Errors.

Troubleshooting.

7. Organizing Your Application.

Including Other Files.

Including Files in a JSP at Runtime. Passing Parameters to an Included File. Including Files from a Servlet.

Forwarding to Another Page.

Forwarding to Another Page from a JSP. Forwarding to Another Page from a Servlet. Passing Parameters to the Forwarded Page.

Passing Java Objects Between JSPs and Servlets. Making Your Application More Modular.

A Reusable HTML Table Module.

The Model-View-Controller Paradigm.

How Does Model-View-Controller Help? An Example Controller. An Example View.

Calling Multiple Controllers and Views. Using an Applet in Your Form. Troubleshooting.

8. More About Saving Data.

Designing the Shopping Cart.

Creating the Data Objects. Creating the ShoppingCart Class. Displaying the Contents of the Shopping Cart. Adding and Removing Items. Completing the Order.

Storing Data in a Cookie.

Using Cookies in Servlets and Java Server Pages.

Troubleshooting.

9. Interacting with JavaBeans.

The jsp:useBean Tag.

Adding the Bean to the Page. Getting Bean Properties. Setting Bean Properties. Setting Properties Directly from Parameters. Initializing a New Bean. The Type of an Existing Bean.

A Bean-Based Web Application. Troubleshooting.

10. Performance.

Making Java Server Pages and Servlets Thread-Safe. Buffering Pages to Improve Performance. Caching Objects to Reduce Setup Time. Precompiling Java Server Pages. Simple Java Optimizations.

Use the StringBuffer class. Parsing Numbers. Creating Objects.

Troubleshooting.

II. CORE COMPONENTS IN-DEPTH.

11. JSP and Servlet Lifecycles.

Servlet Lifecycle.

Servlet Loading. Servlet Initialization. Servlet Execution. Servlet Cleanup.

Java Server Page Lifecycle.

JSP Compilation. JSP Loading. JSP Initialization. JSP Execution. JSP Cleanup.

Reloading Other Classes. Troubleshooting.

12. How the Browser Interacts with the Server.

The HTTP Protocol.

Viewing the Request Headers Made by a Browser.

Common Request Headers.

The Accept Header. The Accept-Language Header. The Accept-Charset Header. The User-Agent Header.

Common Response Headers.

The Content-Type Header. The <F102MO>Content-Length Header. The Cache-Control Header.

The HTTP POST Command. GET Versus <F102MO>POST. HTTPS: Secure HTTP. Troubleshooting.

13. Core Servlet Components.

The ServletRequest Class.

Accessing Request Parameters. Accessing Request Attributes. Accessing Protocol-Related Information. Retrieving Request Data. Handling Uploaded Files. Getting Locale Information.

The HttpServletRequest Class.

Getting Header Values. Getting the HTTP Method. Accessing the Query String. Retrieving Cookies. Getting Session Information.

The ServletContext Class.

Getting the Server Version. Initialization Parameters. Saving Application-Wide Objects. Logging Messages. Calling Other Servlets and JSPs. Accessing Application Resources.

The ServletResponse Class.

Setting the Content Type and Length. Opening an Output Stream. Setting Locale-Specific Information. Response Buffering.

The HttpServletResponse Class.

Setting Header Variables. Redirecting the Browser. Returning Status. Encoding URLs. Sending Cookies.

The ServletInputStream Class. The <F102MO>ServletOutputStream Class. The HttpSession Class.

Storing and Retrieving Objects. Controlling Session Termination. Getting Session Status.

The Cookie Class. Creating a New Cookie.

Setting the Domain and Path. Cookie Aging. Secure Cookies. Cookie Protocol Versions. Cookie Comments.

Troubleshooting.

14. Core Java Server Page Components.

The Built-In JSP Objects.

The request Object. The response Object. The out Object. The session Object. The application Object. The pageContext Object. The config Object. The <F102MO>page Object. The exception Object.

The JspWriter Class.

Sending Output Data. Buffer Control. Using a PrintWriter.

The PageContext Class.

Accessing the Built-In Objects. Accessing Attributes from the PageContext Class. Forwarding and Including.

The JspEngineInfo Class. Troubleshooting.

15. JSP Directives.

The page Directive.

The language Option. The import Option. The session Option. The <F102MO>buffer and autoFlush Options. The isThreadSafe Option. The errorPage Option. The isErrorPage Option. The contentType Option. The info Option. The extends Option.

The include Directive.

The taglib Directive. Troubleshooting.

III. JAVA WEB APPLICATION ARCHITECTURE.

16. Introduction to Application Architecture.

The Three Layers of an Application.

Application Tiers. Applications Come Unglued Over Time. Physical Versus Logical Tiers. How Can You Have Half a Tier? What I Mean by “Tier.”

Single-Tiered Applications. Two-Tiered Applications. Three-Tiered Applications. The Trade-Offs.

Application Complexity. Maintainability. Schedule Pressure. Development Team Skill. Miscellaneous Factors.

Hybrid Architectures.

17. Browser-Server Interaction.

Designing Your Web Screens. Redrawing the Entire Page. Organizing the Presentation into Frames. Sending Data to a Hidden Frame.

Sending Data to the Browser. Handling Multiple Calls.

Troubleshooting.

18. A Single-Tiered Web Application.

Storing and Retrieving Data. Locking a File. Storing Data in a Text File. Storing Data with Object Serialization. Storing Data in a Random Access File. Troubleshooting.

19. Building a Two-Tiered Web Application.

Creating a Connection Pool. Mapping Objects to Database Tables.

A Poor-Man's Object-to-Relational Mapping. An Example Data Object.

A Two-Tiered Problem Reporting System.

The Login Screen. The Main Menu. Querying for Existing Problem Reports. Creating and Updating Problem Reports.

Database Locking. Building a Better Connection Pool. Troubleshooting.

20. Designing a Three-Tiered Application.

Stubs and Skeletons. Single-Client Versus Multi-Client Objects.

Scalability. Maintainability. Striking a Balance.

Optimizing Data Access. Database Locking. Three-Tiered Application with Enterprise JavaBeans.

21. Using RMI in a Web Application.

Using a Single RMI Object for All Requests. Using One Object Per Browser Session. An Example RMI Application.

The Database Interface. The Remote Interfaces. Implementing the ServiceRequests Interface. Implementing the RemoteServiceRequest Interface. Creating the Web Interface. Editing Service Requests.

Troubleshooting.

22. Using CORBA in a Web Application.

Using One CORBA Object for All Sessions. Using Separate CORBA Objects for Each Session.

Using CORBA Structs. Dealing with Null Strings. Alternatives to Null.

An Example CORBA Application. Troubleshooting.

23. Using Enterprise JavaBeans in a Web Application.

What Is Enterprise JavaBeans?

Entity and Session Beans. Containers. Persistence. Transactions. Connection Pooling. Object Pooling.

How EJB, Servlets, and Java Server Pages Fit Together. Creating an Entity Bean.

Creating the Entity Bean Implementation. Creating the Home Interface. Creating the Remote Interface.

Creating a Session Bean. Creating a Stateless Session Bean. Accessing EJBs from Java Server Pages. Packaging a Complete EJB and JSP Application. Troubleshooting.

IV. TAKING JSP AND SERVLETS BEYOND HTML.

24. Creating an XML Application.

A “Hello World” XML Page.

Sending XML from a Java Server Page. Sending XML from a Servlet.

A Few Simple Rules for XML. Why Use XML with JSP and Servlets?

Automatically Generated XML. Parsing XML with SAX and DOM.

Troubleshooting.

25. Adding XSL Stylesheets to Enhance an XML Application.

What Is XSL? A Simple XSL Stylesheet. Navigating an XML Document with XPath. Applying XSL Templates on the Browser. Applying XSL Templates from a Servlet. JSP or Stylesheets? Troubleshooting.

26. Creating a Wireless Web Application.

A Wireless “Hello World” Page.

Viewing the Wireless Hello Page.

A Brief Introduction to WML.

Navigating Between Cards. Creating Input Forms. Processing Form Input.

Detecting Wireless Clients in a JSP or Servlet. A Wireless Score Entry and Reporting System.

Deploying the Scores Application.

Troubleshooting.

27. Creating On-the-Fly Graphics.

Images Aren't Just Static Files. Sending Images from a Servlet. Uploading Images to a Servlet from Java. Uploading Images to a Servlet from a Browser. Performing Online Image Processing.

Adding Captions to Images. Embossing Images. Edge Detection. Lighting Effects.

Troubleshooting.

V. ADVANCED TECHNIQUES.

28. Packaging a JSP Application.

A Simple WAR File Example. Installing a WAR File Under Tomcat. Installing a WAR File Under JRun. WAR Configuration Options.

General Application Options. Servlet Options. Others.

Troubleshooting.

29. Extending JSP with New Tags.

A “Hello World” Tag. Packaging and Installing a Tag. Conditional Includes Using Custom Tags. Accessing Tag Attributes. Processing Body Content with a Custom Tag. Adding Scripting Variables. Troubleshooting.

30. Internationalization.

Detecting the Browser's Preferred Locale. Using Locale-Based Text Formatters.

Creating a Locale Object. Formatting Dates. Formatting Currency. Getting a Locale for a Browser's Preferred Language.

Using Resource Bundles in Web Pages. Troubleshooting.

31. Security.

Role-Based Security. Basic Authentication.

The <F102MO>security-constraint Tag. The login-config Tag.

Creating a Custom Login Form. Checking Security Roles Programmatically. Using Client Certificates for Authentication. Troubleshooting.

32. XML Syntax for JSP.

The XML JSP Syntax. The HelloWorld JSP in XML. Translating XML JSP Syntax. Troubleshooting.

Appendix A. JSP Syntax and API Reference.

JSP Syntax.

Code Scriptlets. Expressions. Declarations. Comments. Directives. Built-In Objects. Actions. XML Syntax. Root Document. Code Scriptlets. Expressions. Declarations. Directives. Tag Libraries.

Java Server Pages API.

javax.servlet.jsp. javax.servlet.jsp.tagext.

Appendix B. Servlet API Reference.

The javax.servlet API.

Interfaces. Classes. Exception.

The javax.servlet.http API.

Interfaces. Classes.

Appendix C. Apache and Tomcat.

Where to Get Tomcat. Installing Tomcat.

Installing Tomcat on Windows. Installing Tomcat on Linux or UNIX.

Running Tomcat Standalone. Running Tomcat Under Netscape Server for Windows. Running Tomcat Under IIS. Running Tomcat Under Apache.

Running Tomcat with Apache for Windows. Running Tomcat with Apache for Linux.

Tomcat Configuration. Working Directory. Logging. Setting the Classpath. Authentication. Special Tomcat Features.

WAR File Installation. JSP Compiler.

Appendix D. Jrun.

Where to Find JRun. Installing JRun for Windows. Installing JRun for Linux. Starting JRun. JRun Administration. Connecting JRun to Other Web Servers.

Connecting JRun to IIS or PWS. Connecting JRun to Netscape Web Server. Connecting JRun to Apache.

Using JRun as a Standalone Web Server. Working Directory. Installing Web Applications. Setting the Classpath. Log Files. JRun Special Features.

Appendix E. ServletExec.

Where to Get ServletExec. Installing the ServletExec ISAPI Plug-In. Installing the ServletExec NSAPI Plug-In. Installing the ServletExec Standalone Server for Windows. Installing the ServletExec Standalone Server for Linux/UNIX. ServletExec Administration. Working Directory. Installing Web Applications. Log Messages. Setting the Classpath. ServletExec Special Features.

Appendix F. Resin.

Where to Get Resin. Installing Resin on Windows.

Unpacking Resin with WinZip. Unpacking Resin from the Command Line. Testing the Installation.

Installing Resin on Linux/UNIX. Running Resin Standalone. Running Resin Under Another Web Server. Running httpd or srun as Windows NT Services. Resin Administration. Working Directory. Installing Web Applications. Logging. Setting the Classpath. Adding Authentication Users. Resin Special Features.

JavaScript Java Server Pages. XSL.

Index.

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020