The J2EETM Tutorial
Home
TOC
Index
PREV TOP NEXT Search
Feedback

What Is a JSP Page?

A JSP page is a text-based 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. A syntax card and reference for the JSP elements are available at:

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

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

Figure 11-1 Localized Date Form

The source code for this example is in the j2eetutorial/examples/src/web/date directory created when you unzip the tutorial bundle. 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:

To build, deploy, and execute this JSP page:

  1. Go to j2eetutorial/examples and build the example by executing ant date (see How to Build and Run the Examples).
  2. Create a J2EE application called DateApp.
    1. Select FileNewApplication.
    2. In the file chooser, navigate to j2eetutorial/examples/src/web/date.
    3. In the File Name field, enter DateApp.
    4. Click New Application.
    5. Click OK.
  3. Create the WAR and add the Web components to the DateApp application.
    1. Select FileNewWeb Component.
    2. Select DateApp from the Create New WAR File In Application combo box.
    3. Enter DateWAR in the WAR Display Name field.
    4. Click Edit.
    5. Navigate to j2eetutorial/examples/build/web/date. Select index.jsp, date.jsp, MyDate.class, and MyLocales.class and click Add, then click Finish.
    6. Click Next.
    7. Click JSP in the Web Component radio button, and then click Next.
    8. Select index.jsp from the JSP Filename combo box. Click Finish.
  4. Enter the context root.
    1. Select DateApp.
    2. Select the Web Context tab.
    3. Enter date.
  5. Deploy the application.
    1. Select ToolsDeploy.
    2. Click Finish.
  6. Invoke the URL http://<host>:8000/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.

Home
TOC
Index
PREV TOP NEXT Search
Feedback