Preface p. xiii Writing Servlets and JSPs p. 1 Writing a Servlet p. 1 Writing a JSP p. 7 Compiling a Servlet p. 10 Packaging Servlets and JSPs p. 11 Creating the Deployment Descriptor p. 14 Deploying Servlets and JSPs p. 17 Deploying an Individual Servlet on Tomcat p. 17 Using a Context Element in Tomcat's server.xml p. 22 Deploying an Individual Servlet on WebLogic p. 24 Deploying an Individual JSP on Tomcat p. 29 Deploying an Individual JSP on WebLogic p. 30 Deploying a Web Application on Tomcat p. 31 Deploying a Web Application on WebLogic Using Ant p. 37 Using the WebLogic Administration Console p. 39 Using WebLogic Builder to Deploy a Web Application p. 43 Using the weblogic.deployer Command-Line Tool p. 46 Naming Your Servlets p. 49 Mapping a Servlet to a Name in web.xml p. 50 Creating More Than One Mapping to a Servlet p. 52 Creating a JSP-Type URL for a Servlet p. 54 Mapping Static Content to a Servlet p. 55 Invoking a Servlet Without a web.xml Mapping p. 57 Mapping All Requests Within a Web Application to a Servlet p. 59 Mapping Requests to a Controller and Preserving Servlet Mappings p. 61 Creating Welcome Files for a Web Application p. 65 Restricting Requests for Certain Servlets p. 66 Giving Only the Controller Access to Certain Servlets p. 71 Using Apache Ant p. 74 Obtaining and Setting Up Ant p. 74 Using Ant Targets p. 76 Including Tomcat JAR files in the Build File Classpath p. 80 Compiling a Servlet with an Ant Build File p. 83 Creating a WAR File with Ant p. 86 Creating a JAR File with Ant p. 89 Starting a Tomcat Application with Ant p. 92 Stopping a Tomcat Application with Ant p. 95 Altering the Format of JSPs p. 98 Precompiling a JSP in Tomcat p. 99 Precompiling a JSP in WebLogic p. 102
Precompiling JSPs with the Precompilation Protocol p. 104 Mapping a JSP to Its Page Implementation Class p. 105 Creating a JSP from Scratch as a JSP Document p. 106 Generating an XML View from a JSP p. 110 Dynamically Including Content in Servlets and JSPs p. 119 Including a Resource Each Time a Servlet Handles a Request p. 120 Using an External Configuration to Include a Resource in a Servlet p. 122 Including Resources Nested at Multiple Levels in a Servlet p. 125 Including a Resource that Seldom Changes into a JSP p. 130 Including Content in a JSP Each Time the JSP Handles a Request p. 133 Using an External Configuration File to Include a Resource in a JSP p. 137 Including an XML Fragment in a JSP Document p. 141 Including Content from Outside a Context in a JSP p. 144 Handling Web Form Data in Servlets and JSPs p. 148 Handling a POST HTTP Request in a Servlet p. 149 Handling a POST HTTP Request in a JSP p. 153 Setting the Properties of a JavaBean in a JSP p. 155 Setting a Scoped Attribute in a JSP to the Value of a Form Parameter p. 158 Posting Data from a Servlet p. 161 Posting Data from a JSP p. 164 Using a Servlet to Add a Parameter to a Query String p. 168 Using a JSP to Add a Parameter to a Query String p. 170 Using a Filter to Read Parameter Values p. 171 Uploading Files p. 174 Preparing the HTML Page for File Uploads p. 175 Using the com.oreilly.servlet Library p. 177 Uploading One File at a Time p. 178 Uploading Multiple Files p. 181 Renaming Files p. 185 Using a JSP to Handle a File Upload p. 187 Handling Exceptions in Web Applications p. 192 Declaring Exception Handlers in web.xml p. 192 Creating an Exception-Handling Servlet p. 196 Sending an Error from a Servlet p. 199 Sending an Error from a JSP p. 201 Creating an Error-Handling JSP p. 202 Declaring a Special Exception-Handling JSP for Other JSPs p. 205 Reading and Setting Cookies p. 209 Setting a Cookie with a Servlet p. 211 Creating an Array from All of the Request's Cookies p. 214 Setting a Cookie with a JSP p. 215
Reading Cookie Values with a Servlet p. 220 Reading Cookie Values with a JSP p. 222 Altering or Removing a Cookie That Has Already Been Set p. 225 Session Tracking p. 227 Setting the Session Timeout in web.xml p. 228 Setting the Session Timeout in All Tomcat Web Applications p. 231 Setting the Session Timeout Programmatically p. 233 Checking if a Session Exists in an HttpServletRequest p. 235 Tracking Session Activity in Servlets p. 237 Tracking Session Activity in JSPs p. 240 Using URL Rewriting in a JSP p. 244 Using URL Rewriting in a Servlet p. 247 Using a Listener to Track the Session Lifecycle p. 251 Using a Listener to Monitor Session Attributes p. 254 Using a Filter to Monitor Session Attributes p. 258 Integrating JavaScript with Servlets and JSPs p. 263 Including JavaScript Modules in a Servlet p. 263 Including JavaScript Modules in a JSP p. 267 Creating a New Window with JavaScript in a Servlet p. 269 Creating a New Window with JavaScript in a JSP p. 272 Using JavaScript to Validate Form Values in a Servlet p. 274 Using JavaScript to Validate Form Values in a JSP p. 277 Sending Non-HTML Content p. 279 Sending a PDF File p. 280 Sending a Word Processing File p. 284 Sending an XML file p. 286 Sending an Audio File p. 289 Viewing Internal Resources in a Servlet p. 292 Logging Messages from Servlets and JSPs p. 296 Logging Without Log4j p. 298 Setting Up Log4j p. 300 Using a Logger Without a Configuration File p. 301 Adding an Appender to the Root Logger p. 304 Using a Pattern with a Logger's Appender p. 306 Using log4j in a JSP p. 310 Logging Messages Using a Servlet Context Event Listener p. 316 Logging Messages Using a Session Event Listener p. 320 Authenticating Clients p. 324 Creating Users and Passwords with Tomcat p. 324 Setting Up SSL on Tomcat p. 325 Using BASIC Authentication p. 328
Using Form-Based Authentication p. 331 Logging Out a User p. 335 Using JAAS to Create a LoginModule p. 337 Creating the JAAS Configuration File p. 344 Using JAAS in a Servlet p. 346 Using JAAS in a JSP p. 349 Binding, Accessing, and Removing Attributes in Web Applications p. 354 Setting ServletContext Attributes in Servlets p. 354 Setting ServletContext Attributes in JSPs p. 357 Accessing or Removing ServletContext Attributes in Servlets p. 360 Accessing or Removing ServletContext Attributes in JSPs p. 362 Setting Session Attributes in Servlets p. 364 Setting Session Attributes in JSPs p. 366 Accessing or Removing Session Attributes in Servlets p. 368 Accessing or Removing Session Attributes in JSPs p. 369 Setting Request Attributes in Servlets p. 371 Setting Request Attributes in JSPs p. 373 Accessing or Removing Request Attributes in Servlets p. 375 Accessing or Removing Request Attributes in JSPs p. 376 Embedding Multimedia in JSPs p. 379 Embedding an Applet in a JSP Using jsp:plugin p. 379 Embedding an Applet in a JSP Using the HTML Converter p. 382 Automatically Creating HTML Template for Including Flash Files p. 386 Writing HTML Template to Embed a Flash File p. 388 Embedding Flash in a Servlet p. 390 Embedding a QuickTime Movie in a JSP p. 392 Embedding an SVG File in a JSP p. 394 Embedding a Background Soundtrack in a JSP p. 396 Working With the Client Request p. 398 Examining HTTP Request Headers in a Servlet p. 398 Examining HTTP Request Headers in a JSP p. 400 Using a Filter to Alter Request Headers p. 402 Automatically Refreshing a Servlet p. 405 Automatically Refreshing a JSP p. 407 Counting the Number of Web Application Requests p. 408 Filtering Requests and Responses p. 411 Mapping a Filter to a Servlet p. 412 Mapping a Filter to a JSP p. 415 Mapping More Than One Filter to a Servlet p. 416 Changing the Order in Which Filters are Applied to Servlets p. 418 Configuring Initialization Parameters for a Filter p. 419
Optionally Blocking a Request with a Filter p. 422 Filtering the HTTP Response p. 424 Using Filters with RequestDispatcher Objects p. 427 Checking Form Parameters with a Filter p. 429 Blocking IP Addresses with a Filter p. 434 Managing Email in Servlets and JSPs p. 439 Placing the Email-Related Classes on your Classpath p. 439 Sending Email from a Servlet p. 441 Sending Email from a Servlet Using a JavaBean p. 444 Accessing Email from a Servlet p. 449 Accessing Email from a Servlet Using a JavaBean p. 454 Handling Attachments from an Email Received in a Servlet p. 455 Adding Attachments to an Email in a Servlet p. 461 Reading a Received Email's Headers from a Servlet p. 466 Accessing Databases p. 471 Accessing a Database from a Servlet Without DataSource p. 472 Configuring a DataSource in Tomcat p. 475 Using a DataSource in a Servlet with Tomcat p. 478 Creating a DataSource on WebLogic p. 481 Using a JNDI Lookup to get a DataSource from WebLogic p. 484 Using a DataSource from WebLogic in a JSP p. 488 Calling a Stored Procedure from a Servlet p. 490 Calling a Stored Procedure from a JSP p. 495 Converting a ResultSet to a Result Object p. 500 Executing Several SQL Statements Within a Single Transaction p. 505 Using Transactions with JSPs p. 511 Finding Information about a ResultSet p. 513 Using Custom Tag Libraries p. 519 Creating a Classic Tag Handler p. 520 Creating a JSP 1.2 TLD for a Classic Tag Handler p. 524 Creating a JSP 2.0 TLD for a Classic Tag Handler p. 526 Packaging a Tag Library in a Web Application p. 529 Packaging the Tag Library in a JAR File p. 530 Using the Custom Tag in a JSP p. 532 Handling Exceptions in a Custom Tag Class p. 533 Creating a Simple Tag Handler p. 536 Creating a TLD for a Simple Tag Handler p. 539 Using a Simple Tag Handler in a JSP p. 541 Creating a JSP Tag File p. 543 Packaging the JSP Tag File in a Web Application p. 545 Packaging the JSP Tag File in a JAR p. 546
Using a Custom Tag Associated with a Tag File p. 547 Adding a Listener Class to a Tag Library p. 548 Using the JSTL p. 551 Downloading the JSTL 1.0 and Using the JSTL Tags in JSPs p. 552 Downloading the Java Web Services Developer Pack p. 554 Using the Core JSTL Tags p. 555 Using the XML Core JSTL Tags p. 558 Using the XML Transform Tags p. 561 Using the Formatting JSTL Tags p. 564 Using A SQL JSTL Tag with a DataSource Configuration p. 567 Using A SQL JSTL Tag Without a DataSource Configuration p. 570 Accessing Scoped Variables with the EL p. 572 Accessing Request Parameters with the EL p. 574 Using the EL to Access Request Headers p. 576 Using the EL to Access One Request Header p. 577 Accessing Cookies with the EL p. 579 Using the EL to Access JavaBean Properties p. 580 Using JSTL Functions p. 585 Internationalization p. 590 Detecting the Client Locale in a Servlet p. 591 Detecting the Client's Locales in a JSP p. 594 Creating a ResourceBundle as a Properties File p. 596 Creating a ResourceBundle as a Java Class p. 597 Using the ResourceBundle in a Servlet p. 599 Using the ResourceBundle in a JSP p. 602 Formatting Dates in a Servlet p. 603 Formatting Dates in a JSP p. 605 Formatting Currencies in a Servlet p. 607 Formatting Currencies in a JSP p. 609 Formatting Percentages in a Servlet p. 610 Formatting Percentages in a JSP p. 612 Setting the Localization Context in the Deployment Descriptor p. 613 Using JNDI and Enterprise JavaBeans p. 615 Configuring a JNDI Object in Tomcat p. 616 Accessing the Tomcat JNDI Resource from a Servlet p. 619 Accessing the Tomcat JNDI Resource from a JSP p. 625 Configuring a JNDI Resource in WebLogic p. 628 Viewing the JNDI Tree in WebLogic p. 630 Accessing the WebLogic JNDI Resource from a Servlet p. 631 Accessing the WebLogic JNDI Resource from a JSP p. 635 Accessing an EJB Using the WebLogic JNDI Tree p. 638
Harvesting Web Information p. 647 Parsing an HTML Page Using the javax.swing.text Subpackages p. 648 Using a Servlet to Harvest Web Data p. 651 Creating a JavaBean as a Web Page Parser p. 656 Using the Web Page Parsing JavaBean in a Servlet p. 659 Using the Web Page Parsing JavaBean in a JSP p. 661 Using the Google and Amazon Web APIs p. 664 Getting Set Up with Google's Web API p. 666 Creating a JavaBean to Connect with Google p. 667 Using a Servlet to Connect with Google p. 671 Using a JSP to Connect with Google p. 675 Getting Set Up with Amazon's Web Services API p. 677 Creating a JavaBean to Connect with Amazon p. 679 Using a Servlet to Connect with Amazon p. 684 Using a JSP to Connect with Amazon p. 688 Index p. 691 Table of Contents provided by Blackwell's Book Services and R.R. Bowker. Used with permission.