Preface

JavaServer Pages™ (JSP) is a new technology for web application development that has received a great deal of attention since it was first announced.

Why is JSP so exciting? One reason is that JSP is Java-based, and Java is well-suited for enterprise computing. In fact, JSP is a key part of the Java™ 2 Enterprise Edition (J2EE) platform and can take advantage of the many Java Enterprise libraries, such as JDBC, JNDI, and Enterprise JavaBeans™.

Another reason is that JSP supports a powerful model for developing web applications that separates presentation from processing. Understanding why this is so important requires a bit of a history lesson. In the early days of the Web, the only tool for developing dynamic web content was the Common Gateway Interface (CGI). CGI outlined how a web server made user input available to a program, as well as how the program provided the web server with dynamically generated content to send back. CGI scripts were typically written in Perl. (In fact, CGI Perl scripts still drive numerous dynamic web sites.) However, CGI is not an efficient solution. For every request, the web server has to create a new operating-system process, load a Perl interpreter and the Perl script, execute the script, and then dispose of the entire process when it’s done.

To provide a more efficient solution, various alternatives to CGI have been added to programmers’ toolboxes over the last few years: FastCGI, for example, runs each CGI program in an external permanent process (or a pool of processes). In addition, mod_ perl for Apache, NSAPI for Netscape, and ISAPI for Microsoft’s IIS all run server-side programs in the same process as the web server itself. While these solutions offer better performance and scalability, each one is supported by only a subset of the popular web servers.

The Java Servlet API, introduced in early 1997, provides a solution to the portability issue. However, all these technologies suffer from a common problem: HTML code embedded inside programs. If you’ve ever looked at the code for a servlet, you’ve probably seen endless calls to out.println( ) that contain scores of HTML tags. For the individual developer working on a simple web site this approach may work fine, but it makes it very difficult for people with different skills to work together to develop a web application.

This is becoming a significant problem. As web sites become increasingly complex and are more and more critical to the success of an organization, the appearance and usability of the web interface becomes paramount. New client technologies, such as client-side scripts and DHTML, can develop more responsive and interactive user interfaces, stylesheets can make it easier to globally change fonts and colors, and images can make the interface more appealing. At the same time, server-side code is getting more complex, and demands for reliability, performance, and fault tolerance are increasing. The growing complexity of web applications requires a development model that allows people with different skills to cooperate efficiently.

JavaServer Pages provides just such a development model, allowing web page authors with skills in graphics, layout, and usability to work in tandem with programmers who are experienced in server-side technologies such as multithreading, resource pooling, databases, and caching. While there are other technologies, such as ASP, PHP, and ColdFusion, that support similar development models, none of them offers all the advantages of JSP.

What’s in This Book

This book covers Version 1.1 of the JavaServer Pages specification, which was released in late 1999.

In this book, you will learn how to use all the standard JSP elements and features, including elements for accessing JavaBeans components, separating the processing over multiple pages to increase reusability and simplify maintenance, and sharing information between pages, requests, and users. You will also learn how to use and develop custom components. A rich set of custom components, for tasks such as integration of database data, internationalization, access control, and conditional processing, is described in detail. Many of these components are generic enough that you can reuse them directly in your own applications.

The examples in this book guide you through solutions to common JSP design problems, from basic issues such as retrieving and validating user input, to more advanced areas such as developing a database-driven site, authenticating users, providing personalized content, and implementing internationalization. The last part of the book describes how you can combine JSP with other Java technologies; in particular, I describe the combination of JSP and servlets and provide an overview of how JSP fits into the larger scope of J2EE.

Get Java Server Pages now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.