- Shopping Bag ( 0 items )
Learn to deliver dynamic content to Web pages using JavaServer Pages. The ideal introduction to this server-side scripting language, JSP: A Beginner's Guide first covers the building blocks, such as JSP syntax, scripting elements, implicit objects, and tag libraries.
Part 1: JSP Foundations
Ease of Application Installation, Deployment, and Training
Web applications require no installation beyond installation of the browser. (And these days, the browser is often bundled with the operating system.) The popularity of the Web browser has also achieved a kind of critical mass-so many applications use a browser that people understand and feel comfortable with the browser as their platform. People rarely need much training in the mechanics of using a Web browser.
The popularity of browser applications does not mean that users are completely happy with their limitations. Most recent developments in the browser and the Web server aim to overcome the limits of the basic Web technology. Although this book describes JavaServer Pages, a server technology, let us briefly address browser technologies.
The MIME standard that provides the basic scheme for HTTP request formatting also provides the basis for launching helper applications. The idea is that the browser passes MIME format types that it cannot handle to helper applications.
Recently, helper application functionality has tended to migrate into browser plug-ins. We discuss plug-ins next.
Browser plug-ins seamlessly extend browser functionality so that they appear to be part of the browser itself. For example, Adobe Software provides a plug-in for viewing Adobe's Portable Document Format (PDF). Other plug-ins support audio and video formats. Real Networks, for example, has plug-ins to play RealAudio and RealVideo files directly in the browser. Dozens of such plug-in programs now exist for both Netscape and Internet Explorer. Such plug-ins are loaded into the browser's own address space for execution. Vendors deploy plug-ins in browsers as shared libraries.
Shared libraries are specially packaged units of code (usually written in C or C++) that can be loaded and executed in an application at runtime. On Microsoft Windows platforms, shared libraries use Microsoft's Dynamic Link Library (DLL) format that has a All file extension. On UNIX platforms, shared libraries use the Dynamic Shared Object (DSO) format that has a .so file extension.
Dynamic HTML also provides access to a browser page's Document Object Model (DOM). DOM is the internal representation of the elements of a page, along with their attributes. Dynamic HTML supports runtime access to some of these elements and in some cases, enables runtime modifications. For example, suppose we have this page element:
...HTML has a low level of standardization. Microsoft added support for its proprietary technologies, ActiveX and VBScript, which Netscape does not support. Both Netscape and Internet Explorer support CSS, but to different degrees for different features. Both the event model and DOM for Internet Explorer and Netscape differ, making cross-platform use of DHTML quirky. (See http : / /www. dhtml zone. com/.)
From that quiet beginning as Oak, Java has captured unprecedented mindshare among programmers. Initially, this popularity focused on the client side, especially Java applets.
The idea behind applets was to provide full-featured programming capabilities to browser applications without sacrificing security. Both Netscape and Microsoft licensed Java and integrated it into their respective browsers. Today, Sun provides a Java plug-in for both browser platforms. Special HTML tags invoke the plug-in to load applets into a Java virtual machine (JVM). This plug-in bridges the browser and an external JVM. The Sun Java plug-in removes developer dependence on the "out-of-the-box" versions of the Java Virtual MaclAne supported by browser vendors. This allows developers to remain current with the Java releases. For example, at this time you must use the Sun plug-in to run Java 2 applets in a browser....
|Pt. I||JSP Foundations|
|1||Introduction to Internet Technologies||3|
|2||JSP Elements: Comments and Directives||43|
|3||JSP Elements: Scripting Elements||75|
|Pt. II||Building Real-World Applications|
|9||Controller and Flow Control in Web Applications||335|
|10||Integrating a Database||377|
|App. A: Mastery Check Answers||429|
|App. B||Creating a Development and Deployment Environment||451|
|App. C||Creating a MySQL Database||471|
|App. D||New Features in JSP 1.2||481|
Do you develop Web sites and wish you could improve the performance of your CGI scripts? Have you ever wanted to use program loops or variables directly in your Web pages? Do you grow weary of writing obscure Perl programs that exert much of their effort printing out static HTML?
Do you develop Java servlets to generate Web pages? Do you yearn for a more natural way to write dynamic pages? Do you seek a clean way to separate programming language constructs from HTML elements?
Do you develop Active Server Pages (ASP) and hope to create Web sites on non-Microsoft platforms? Do you think there is a market for your skills on UNIX?
Are you interested in design patterns and wonder how you should apply them to Web architectures?
If you answered yes to any of these questions, this book is for you! The JavaServer Pages technology was developed by Sun Microsystems, Inc. Most obviously, the technology provides a better way to write dynamic Web pages. Web page development must often include both static HTML and dynamic content in its pages. Suppose, for example, you want to target the content of a page specifically for the person accessing the page. Most of the page provides the same look-and-feel for every person who accesses it. But some part of the page pulls content from a database tailored by user demographics or a pre-established login identity. Amazon.com, for example, provides a welcome message with a user's name and targeted advertisements. How might we imitate Amazon.com?
Traditional CGI development uses a programming language, probably Perl or C/C++, to create a program that prints out large amounts of static HTML interleaved with responses from database queries. Even Java servlets (a companion Java technology) follow this basic paradigm; the only difference is that servlets live in a process thread, while Perl scripts execute as standalone processes. JavaServer Pages invert this approach, starting with static HTML and interleaving "tagged" Java code into the static HTML. The fact that the Java code is "tagged" is important-it means there is a clear separation between HTML and code. Consider the following JSP fragment (don't worry about the details right now): This JSP fragment consists of two Java code sections and an HTML section. The point to notice is that we insert both HTML and Java using tags. Of course, what goes between the Java tags is more complicated than what goes between the HTML tags, but we will show later on in Modules 5 and 6 how even Java scripting can be simplified using JSP.
Now look at this servlet code fragment doing the same job performed by the JSP fragment: This servlet fragment buries static HTML in a Java println function call. The little piece of HTML shown here is comprehensible, but it is easy to see how confusing such statements can become. The problem lies with the inability of servlets to separate Java code from static HTML. It is the same problem when using Perl or C/C++ CGI scripts. JavaServer Pages solve this problem.
Part I lays the technical foundations for building JavaServer Pages, focusing on syntax elements and their appropriate use. We divide Part I into six modules addressing the foundations of Internet technologies and each of the specific elements of JavaServer Pages.
Part II introduces fundamental aspects of practical JSP development and focuses on the issues and techniques necessary to build "real-world" JSP applications. We divide Part II into four modules addressing common software patterns in Web architectures, Web security, application workflow, Ind integration of databases. By using such patterns, Web developers can create Web applications more quickly with fewer errors.
Part III provides four appendices supplying ancillary information supporting our basic discussion.
Module 2 narrows the focus to two JSP syntax elements, comments and directives, and their appropriate use in Web applications. Module 2 also describes the basics of a JSP page and lays the foundations for good programming style. At the end of Module 2, you will have built and displayed your first simple JSP page.
Module 3 describes JSP scripting elements. We showed a few examples earlier in this Introduction. In Module 3 we describe scripting elements in detail and begin to build more complex JSP application elements. At the end of Module 3 you will be able to build complete JSP applications that exploit Java to script dynamic content.
Module 4 describes implicit objects in JavaServer Pages. These objects provide a framework for passing and using information between the parts of a JSP application. At the end of Module 4 you will have built a JSP page that interactively responds to an HTML form.
Module 5 describes standard JSP actions. JSP actions function as callouts (external references) to Java functionality. Among other things, standard actions provide a simple mechanism for incorporating helper JavaBeans in one's application. At the end of Module 5 you will be able to incorporate JavaBeans into your JSP application, thereby improving its style and professionalism.
Module 6 presents custom JSP actions. Such actions provide one of the most powerful features of the JSP architecture. When writing custom JSP actions one is really extending the JSP engine itself. At the end of Module 6 you will have built your first such extension to the JSP engine.
Module 8 addresses security issues. We describe some of the common security techniques used in Web architectures, including those required by the Servlet 2.2 specification. Module 9 describes issues surrounding application workflow-the control and movement from page to page in a JSP application.
Module 10 addresses the role of databases in JSP architectures. We describe the JDBC data access API. Then we describe various techniques required to integrate a database into a JSP application.
Appendix C describes how to set up and configure a MySQL database. This database engine is free and provides a fine platform for personal development projects.
Finally, Appendix D describes the changes that occur between the current JSP specification JSP 1.1) and the proposed final daft of the JavaServer Pages 1.2 specification.
Most modules contain Ask the Expert question-and-answer sections to address potentially confusing issues. Each module contains step-by-step Projects to give you a chance to practice the concepts taught thus far. You can download the content for the projects from Osborne's Web site (www. osborne. com).
Mastery Checks are included at the end of all modules to give you another chance to review the concepts taught in the module. The answers to the Mastery Checks are in Appendix A.