With literally hundreds of examples and thousands of lines of code, the Java Servlet and JSP Cookbook yields tips and techniques that any Java web developer who uses JavaServer Pages or servlets will use every day, along with full-fledged solutions to significant web application development problems that developers can insert directly into their own applications. Java Servlet and JSP Cookbook presents real-world problems, and provides concise, practical solutions to each. Finding even one tested code "recipe" that solves a gnarly problem in this comprehensive collection of solutions and best practices will save hours of frustration--easily justifying the cost of this invaluable book. But "Java Servlet and JSP Cookbook" is more than just a wealth of cut-and-paste code. It also offers clear explanations of how and why the code works, warns of potential pitfalls, and directs you to sources of additional information, so you can learn to adapt the problem-solving techniques to similar situations. These recipes include vital topics like the use of Ant to setup a build environment, extensive coverage of the WAR file format and web.xml deployment descriptor, file-uploading, error-handling, cookies, logging, dealing with non-HTML content, multimedia, request filtering, web services, I18N, web services, and a host of other topics that frustrate even the most seasoned developers.For Java web developers of all levels who are eager to put into practice the theory presented in other API-focused books, the solutions presented in this practical book will prove invaluable over and over again. This is painless way for less experienced developers who prefer to learn by doing to expand their skills and productivity, while accomplishing practical solutions to the pressing problems they face every day. More experienced developers can use these recipes to solve time-consuming problems quickly, freeing up their time for the more creative aspects of their work.
Preface; 1. Writing Servlets and JSPs; 1.1 Writing a Servlet 1.2 Writing a JSP; 1.3 Compiling a Servlet; 1.4 Packaging Servlets and JSPs; 1.5 Creating the Deployment Descriptor; 2. Deploying Servlets and JSPs 2.1 Deploying an Individual Servlet on Tomcat; 2.2 Using a Context Element in Tomcat's server.xml 2.3 Deploying an Individual Servlet on WebLogic; 2.4 Deploying an Individual JSP on Tomcat; 2.5 Deploying an Individual JSP on WebLogic; 2.6 Deploying a Web Application on Tomcat; 2.7 Deploying a Web Application on WebLogic Using Ant; 2.8 Using the WebLogic Administration Console; 2.9 Using WebLogic Builder to Deploy a Web Application; 2.10 Using the weblogic.Deployer Command-Line Tool; 3. Naming Your Servlets; 3.1 Mapping a Servlet to a Name in web.xml; 3.2 Creating More Than One Mapping to a Servlet 3.3 Creating a JSP-Type URL for a Servlet; 3.4 Mapping Static Content to a Servlet; 3.5 Invoking a Servlet Without a web.xml Mapping; 3.6 Mapping All Requests Within a Web Application to a Servlet; 3.7 Mapping Requests to a Controller and Preserving Servlet Mappings; 3.8 Creating Welcome Files for a Web Application 3.9 Restricting Requests for Certain Servlets; 3.10 Giving Only the Controller Access to Certain Servlets; 4. Using Apache Ant 4.1 Obtaining and Setting Up Ant; 4.2 Using Ant Targets 4.3 Including Tomcat JAR files in the Build File Classpath 4.4 Compiling a Servlet with an Ant Build File; 4.5 Creating a WAR File with Ant; 4.6 Creating a JAR File with Ant; 4.7 Starting a Tomcat Application with Ant; 4.8 Stopping a Tomcat Application with Ant; 5. Altering the Format of JSPs; 5.1 Precompiling a JSP in Tomcat; 5.2 Precompiling a JSP in WebLogic; 5.3 Precompiling JSPs with the Precompilation Protocol; 5.4 Mapping a JSP to Its Page Implementation Class; 5.5 Creating a JSP from Scratch as a JSP Document; 5.6 Generating an XML View from a JSP; 6. Dynamically Including Content in Servlets and JSPs; 6.1 Including a Resource Each Time a Servlet Handles a Request; 6.2 Using an External Configuration to Include a Resource in a Servlet; 6.3 Including Resources Nested at Multiple Levels in a Servlet; 6.4 Including a Resource that Seldom Changes into a JSP; 6.5 Including Content in a JSP Each Time the JSP Handles a Request; 6.6 Using an External Configuration File to Include a Resource in a JSP; 6.7 Including an XML Fragment in a JSP Document; 6.8 Including Content from Outside a Context in a JSP; 7. Handling Web Form Data in Servlets and JSPs 7.1 Handling a POST HTTP Request in a Servlet; 7.2 Handling a POST HTTP Request in a JSP; 7.3 Setting the Properties of a JavaBean in a JSP; 7.4 Setting a Scoped Attribute in a JSP to the Value of a Form Parameter; 7.5 Posting Data from a Servlet; 7.6 Posting Data from a JSP; 7.7 Using a Servlet to Add a Parameter to a Query String 7.8 Using a JSP to Add a Parameter to a Query String; 7.9 Using a Filter to Read Parameter Values; 8. Uploading Files;; 8.1 Preparing the HTML Page for File Uploads; 8.2 Using the com.