Chapter 24 JavaServer Pages


Jaguar support of JSP

For JSPs to run in Jaguar, they must belong to a Web application. In addition, you can map servlets to JSPs. When the servlet is called, the corresponding JSP is invoked. This section discusses:

JSP and Jaguar overview

Jaguar fully supports the features described in the JavaServer Pages 1.1 specification as well as mapping requests to JSPs as described in the Java Servlet 2.2 specification. In Jaguar the JSP Engine is implemented as a generic servlet, which is referred to as the JSP servlet. The JSP servlet handles runtime translation and compilation of JSPs, if required, as well as invoking the generated servlet for a given JSP.

The JSP servlet supports translation of JSPs containing JSP standard directives, standard actions, custom tags and scripting elements such as declarations, scriptlets and expressions. For JSPs that include custom JSP tags, a tag handler is loaded every time it is needed. Tag handlers are not pooled. The JSP servlet also supports all the semantics associated with the "extends" attribute.

A Web application is a collection of resources that is mapped to a specific Uniform Resource Identifier (URI) prefix. These resources may include JSPs, servlets, HTML files, and images. The URI that is stored in the request data structure is used to retrieve a JSP page. The JSP Servlet creates a unique name for a generated servlet. Generated servlet names are stored in a hash table. For a given request URI, the JSP Servlet determines which generated servlet name it corresponds to. It then looks up the generated servlet name in the hash table; an entry in the hash table indicates that the JSP page has been precompiled.

If a JSP page is not precompiled, the JSP servlet invokes the compiler and saves the generated files in the appropriate directory. It then executes the page by invoking the _jspService method on the generated servlet.

If a JSP page is precompiled, the JSP servlet compares the timestamp of the JSP page and all its nested include files, if any, with the timestamp of the generated servlet. If any time stamp of the JSP page is more recent than that of the generated servlet, the JSP page is recompiled. If the generated servlet is current, the JSP Servlet creates a new instance of the precompiled servlet class and calls _jspService method on it.

The JSP Servlet uses CLASSPATH from ServletConfig for compiling the generated servlet. To change the directory where servlets are generated, set the "scratchdir" parameter as one of the parameters in ServletConfig. "scratchdir" is passed to the "init" method on the JSP Servlet; you can set it by using one of the init-args on the Servlet Properties tab.

Compiling JSPs

When you create a JSP using Jaguar Manager, the load during startup option determines if your JSPs are compiled at server start-up or when the JSP is first called. You can also use a command-line utility to compile your JSPs independent of the Jaguar server. This allows you to debug and test your JSPs without running the server. This section describes the JSP compiler supplied with your Jaguar installation.

jspc compiler

The %JAGUAR%\bin\jspc.bat (NT) and $JAGUAR/bin/jspc.sh (Solaris) compiler provides you with several options for compiling your JSPs. This section uses jspc.sh for demonstration purposes. All options are valid for both systems.

Usage

                    jspc.sh <options> <jsp files>|<jsp dirs> 

options include:

jsp files include any number of:

Examples

This section provides examples of the various jspc compiler options:

jspc.sh -webapp MyWebApp /pets/cat.jsp /pets/dog.jsp

The compiler identifies the $JAGUAR/Repository/WebApplication/MyWebApp directory as the Web application directory and compiles the cat.jsp and dog.jsp files located in the $JAGUAR/Repository/WebApplication/MyWebApp/pets directory.

jspc.sh -uriroot $JAGUAR/Repository/WebApplicaton/MyWebApp -d $JAGUAR/work /pets/cat.jsp /pets/dog.jsp

The compiler identifies the $JAGUAR/Repository/WebApplication/MyWebApp directory as the Web application directory and compiles the cat.jsp and dog.jsp files, which are located in the pets subdirectory, and outputs the results to the $JAGUAR/work directory.

jspc.sh -uriroot $JAGUAR/Repository/WebApplicaton/MyWebApp -d $JAGUAR/work -jspdir $JAGUAR/Repository/WebApplicaton/MyWebApp

The compiler identifies the $JAGUAR/Repository/WebApplication/MyWebApp directory as the Web application directory and compiles all JSP files contained in it and any subdirectories, and outputs the results to the $JAGUAR/work directory.

jspc.sh -uriroot $JAGUAR/Repository/WebApplicaton/MyWebApp -d $JAGUAR/work -keep /pets/dog.jsp /pets/cat.jsp

the -keep option notifies the compiler to keep all generated Java files in the output directory, along with the compiled JSP files.

JSP file locations

JSPs are contained within Web applications. JSP source code and class files are stored relative to the Web application to which it belongs.

Saving Java source code

Normally, Jaguar deletes the Java source code after compiling a JSP. To keep the generated source code to view or use in a debugger:

  1. Display the properties for the Web application in which the JSP is installed.
  2. On the All Properties tab, set the com.sybase.jaguar.webapplication.keepgenerated property to "true". The generated Java files will be saved in $JAGUAR\work\<server>\Servlet\<webappName>, where <server> is the name of your Jaguar server, and <webappName> is the name of your Web application.

Class file locations

Jaguar generates JSP servlet classes in Jaguar_home/Repository/WebApplication/app-name/work, where app-name is the name of the Web application.

Creating JSPs in Web applications

  1. In Jaguar Manager, select the Web Application folder.
  2. Select an existing Web application to which you are adding a JSP. If a Web application does not already exist, you must create one by selecting File | New Web Application.
  3. Select File | New Web Component. Enter the name of the Web component (JSP) and click OK.
    Jaguar creates the JSP under the Web applications folder. For example, if you name your JSP testjsp and it belongs to the MyWebApp application, then the location is Jaguar_home/Repository/WebApplication/MyWebApp/testjsp.

    If you have existing JSPs that you want to add to your Web application or if you create JSPs with another editing tool, you can copy them to this location, making sure the JSP you copy and the name you enter for the JSP match.
  4. To configure your JSP, double-click the JSP or highlight the JSP and select File | Web Application Component Properties. Complete the information described below.

  5. To configure security for your JSP, see Chapter 25, "Configuring Web Application Security".

Editing JSPs

Jaguar supplies an editor for creating and modifying your JSP files; however, you can use any text editor to perform the same tasks.

Steps To edit your JSPs:

  1. Open the Web Application folder and select the Web application to which the JSP belongs.

  2. Highlight the JSP.

  3. Select File | Edit JSP. An editor displays where you can view and modify your JSP. Locate other files for editing by selecting File | Open. When you are finished, select File | Save.


Steps To delete a JSP:

  1. Open the Web Application folder and select the Web application to which the JSP file belongs.

  2. Highlight the JSP.

  3. Select File | Delete Web Application Component.


Internationalization

Jaguar supports international versions of your Web application resources: Servlets, static Web pages, and so on. Refer to Chapter 23, "Creating Java Servlets" for information on configuring and accessing international versions of your Web resources.

Mapping JSPs

Jaguar supports path mappings as described in the Java Servlet 2.2 specification. Mappings are defined at the Web application level. Refer to Chapter 22, "Creating Web Applications" for information about Request path mappings.

 


Copyright © 2000 Sybase, Inc. All rights reserved.