A JSP page is a text-based document that describes how to process a request to create a response . The description intermixes template data with some dynamic actions and leverages on the Java platform. The features in the JSP technology support a number of different paradigms for authoring of dynamic content; some of them are described in Section JSP.1.6. The next couple of examples only attempt to present the technical components of the JSP specification and are not prescribing "good" or "bad" paradigms. JSP.1.2.1 An Example Using Scripting and BeansA simple example of a JSP page is shown in Figure JSP.1-1. The example shows the response page, which is intended to be a short list with the day of the month and year at the moment when the request is received. The page itself contains fixed template text and additional elements described by the JSP specification that are shown underlined in the figure. As the request reaches the page, the response is created based on the template text. As the first element is reached, a server-side bean object is created with name clock and type calendar.jspCalendar. This object can be used and modified later in the page. In particular, the next two elements access properties of the object and insert these values into the response page as strings. Figure JSP.1-1. A JSP Page Using Beans and Scripting
JSP.1.2.2 An Example Using a Tag LibraryFigure JSP.1-2 is another example of a JSP page. This page uses custom actions to create the server-side object and then to produce the response data. In the example, a taglib directive first makes available into this page a tag library for database queries. The directive indicates the tag library to use and provides a prefix to use locally in this page to name those actions. Figure JSP.1-2 A JSP Page Using Custom Actions<html> <%@ taglib uri="http://acme.com/taglibs/simpleDB.tld" prefix="x" %> <x:queryBlock connData="conData1"> <x:queryStatement> SELECT ACCOUNT, BALANCE FROM ... </x:queryStatement> The top 10 accounts and balances are: <table> <tr><th>ACCOUNT</th><th>BALANCE</th></tr> <x:queryCreateRows from="1" to="10"> <td><x:queryDisplay field="ACCOUNT"/></td> <td><x:queryDisplay field="BALANCE"/></td> </x:queryCreateRows> </table> </x:queryBlock> </html> Designing tag libraries is a delicate effort, analogous to that of designing a language; we are making no special effort here to define tags that are useful for any but pedagogical purposes. For the purposes of this example, we will assume that this fictitious tag library introduces four actions:
In this example:
JSP.1.2.3 Components and ContainersThe JavaServer Pages technology builds on the servlet standard extension. JavaServer Pages is a standard extension that is defined extending the concepts in the servlet standard extension. JSP 1.1 uses the classes from Java Servlet 2.2 specification. JSP pages and servlet classes are collectively referred to as web components . JSP pages are delivered to a container that provides the services indicated in the JSP component contract . JSP 1.1 and Servlet 2.2 rely only on features in the Java Runtime Environment 1.1, although they are compatible with, and can take advantage of, the Java 2 Runtime Environment. |