Download
FAQ
History
PrevHomeNext API
Search
Feedback
Divider

What Is a JSP Page?

A JSP page is a text document that contains two types of text: static template data, which can be expressed in any text-based format, such as HTML, SVG, WML, and XML, and JSP elements, which construct dynamic content.

The recommended file extension for the source file of a JSP page is .jsp. The page may be composed of a top file that includes other files that contain either a complete JSP page or a fragment of a JSP page. The recommended extension for the source file of a fragment of a JSP page is .jspf.

The JSP elements in a JSP page can be expressed in two syntaxes--standard and XML--though any given file can only use one syntax. A JSP page in XML syntax is an XML document and can be manipulated by tools and APIs for XML documents. The chapters in this tutorial that cover JSP technology currently document only the standard syntax. The XML syntax will be addressed in a future release of the tutorial. A syntax card and reference that summarizes both syntaxes is available at

http://java.sun.com/products/jsp/docs.html#syntax 

Example

The Web page in Figure 16-1 is a form that allows you to select a locale and displays the date in a manner appropriate to the locale.

Localized Date Form

Figure 16-1 Localized Date Form

The source code for this example is in the <INSTALL>/jwstutorial13/examples/web/date/ directory. The JSP page, index.jsp, used to create the form appears below; it is a typical mixture of static HTML markup and JSP elements. If you have developed Web pages, you are probably familiar with the HTML document structure statements (<head>, <body>, and so on) and the HTML statements that create a form (<form>) and a menu (<select>).

The lines in bold in the example code contain the following types of JSP constructs:

A sample date.war is provided in <INSTALL>/jwstutorial13/examples/web/provided-wars/. To build, package, deploy, and execute this example:

  1. In a terminal window, go to <INSTALL>/jwstutorial13/examples/web/date/.
  2. Run ant build. This target will spawn any necessary compilations and copy files to the <INSTALL>/jwstutorial13/examples/web/date/build/ directory.
  3. Start Tomcat.
  4. Run ant install. The install target notifies Tomcat that the new context is available.
  5. Set the character encoding in your browser to UTF-8.
  6. Open the URL http://localhost:8080/date in a browser.

You will see a combo box whose entries are locales. Select a locale and click Get Date. You will see the date expressed in a manner appropriate for that locale.

Divider
Download
FAQ
History
PrevHomeNext API
Search
Feedback
Divider

All of the material in The Java(TM) Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.