Chapter 22 Creating Web Applications


Configuring Web application properties

You can configure a Web application's properties in Jaguar Manager. If you have created a Web archive (WAR) file using another tool and imported it into Jaguar, most properties are automatically set during the import process.

Steps To display the Web Application Properties dialog box

The procedures in this section require you to start with the Web Application Properties dialog box open. Display it as follows:

  1. Expand the Web Applications folder, then highlight the icon that represents your application.

  2. Choose File | Web Application Properties.


General properties

General properties are as follows:

Context initialization properties

All servlets and JSPs in a Web application share a common set of context initialization properties specified by the deployment descriptor. Servlet code can retrieve the values by calling the getInitParamers() and getInitParameterNames() methods in interface javax.Servlet.ServletContext.

Environment properties can be used for the same purpose as context-initialization properties, and allow additional datatypes besides java.lang.String. See "Environment properties" for more information.

Steps To configure context initialization properties:

  1. Display the Context Params tab in the Web Application Properties dialog box.

  2. A list of properties and values appears. You can create, modify, and delete properties as follows:


Welcome and error page specifications

You can customize the list of welcome files and error-response files in your application. These settings take effect when Web clients are browsing in your application's subset of the server's URL namespace.

Welcome files

Welcome files are used to satisfy HTTP requests that end in a directory name, rather than specifying the full path to a file or a path that is mapped to a servlet invocation. For each request that maps to a directory, the server searches the directory for files that occur in the Web application's list of welcome files, in the listed order. For example, if the welcome-file list is "index.html, index.htm, welcome.jsp", the server looks for index.html, then index.htm, then welcome.jsp. If the server finds a static file on the welcome-file list, the server returns its content. If a JSP on the welcome-file list exists, the server invokes the JSP. If no match exists in the directory, the server returns an HTTP 404 (file not found) error, because Jaguar does not support directory listings.

Steps To add a welcome file:

  1. Display the File Refs tab in the Web Application Properties dialog box.

  2. Click Add. A new row appears in the list of welcome files.

  3. Place the cursor in the new row, and enter the name of the welcome file. Welcome files are plain files, without path information. You can prepend a directory separator (/), which will be ignored. For example, /index.html is the same as index.html.


Steps To delete a welcome file:

  1. Display the File Refs tab in the Web Application Properties dialog box. The welcome-file list displays.

  2. Place the cursor in the row to be deleted, then click Delete.


Error pages

Error pages allow you to customize the response that the server sends to Web clients when an error occurs. You can specify HTML files to send in response to HTTP error codes and to Java exceptions thrown in JSPs or servlets.

When an exception is thrown, servlet engine will search the error page mappings for the exception and its super classes. For example, assume AException extends BException and BException extends CException and CException extends java.lang.Exception. When AException is thrown, Jaguar checks if AException is mapped. If not, Jaguar checks if BException is mapped, and so forth.

Steps To add an error page:

  1. Display the File Refs tab in the Web Application Properties dialog box.

  2. Under Error Mapping, click Add. A new row is added to the mapping table with default settings.

  3. Place the cursor in the Error/Exception cell, and type the HTTP error number or Java exception class name.

  4. Place the cursor in the URL cell, and type the path to the file relative to the Web application's context root. For example, /etc/error404.html.

  5. Verify that the file exists in your Jaguar installation directory and can be read by the Jaguar server process. For example, the path /etc/error404.html corresponds to this file in your Jaguar installation directory, where web_app is the name of the Web application:
    Repository/WebApplication/web_app/etc/error404.html



Tag library descriptor references

JSPs can use tag libraries to serve content formatted with custom tags. The tag library is a Java class with methods to parse content that is tagged with custom tags and output formatted content to be returned in the response stream. Each tag library must have a Type Library Descriptor (TLD) file that describes the available tags and specifies the corresponding Java classes and methods.

JSPs use a type library by specifying the location of the TLD file as a URL. In your Web application, you can specify a mapping so that TLD URLs in JSPs map to a local URL. For example, you may refer to a tag library as follows in a JSP:

<%@ taglib uri="/example.tld" prefix="ex" %>

This path can be mapped to another location, such as:

/WEB-INF/tlds/PRlibrary_1_4.tld

You do not have to map TLD URLs in the Web application. If there is no mapping that matches a TLD URL, Jaguar loads the file at the URL specified in the JSP and raises an error if the file does not exist.

Mapping TLD URLs provides several benefits such as:

In an XML deployment descriptor, TLD URL mappings are specified by taglib elements.

Note   Tag library classes A Web application's tag library classes must be deployed in the WEB-INF/lib or WEB-INF/classes directories, with the other Java classes required by your Web application. See "Java classes" for more information.

Steps Configuring TLD mappings in Jaguar Manager

  1. Display the All Properties tab in the Web Application Properties dialog box.

  2. If necessary, add an entry for the property com.sybase.jaguar.webapplication.taglib . Otherwise, modify the existing value for this property.

  3. In the property value, specify each mapping as follows:
    (taglib-uri=alias, taglib-location=real-path)


    Where alias is the path used in JSP source code, and real-path is the TLD files location relative to the Web application's context root.

    If multiple mappings are required, separate each by a comma. For example (the following must be entered without line breaks or carriage returns):
    (taglib-uri=taglib.tld, taglib-location=TLD/abctaglib.tld),
    (taglib-uri=lib2.tld,taglib-location=TLD/lib2v2.tld)



Naming references

Web applications allow you to use logical names for JNDI lookups in your servlet and JSP code. Logical names allow your application to run in environments where the JNDI name space does not match the names hard coded in your application. When deploying an application, you can map the logical names to actual names that match the server's configuration.

When developing an application, you must use JNDI to obtain database connections, mail sessions, and EJB proxies. You must catalog the JNDI names used by your code in the application's deployment descriptor.

All logical JNDI names used in your application must be prefixed with java:comp/env. The J2EE specification requires the following hierarchy, based on resource type:

EJB references

Servlets and JSPs use EJB references to instantiate proxies for EJB home interfaces. See Chapter 8, "Creating Enterprise JavaBean Clients," in the Jaguar CTS Programmer's Guide for more information. EJB references must be cataloged in the deployment descriptor so that the Web application can run independent of a specific naming configuration. When deploying the Web application, a site administrator can specify site-specific EJB home names.

Servlets and JSPs can look up an EJB by specifying the reference name prefixed with java:comp/env/. For example, if you enter ejb/catalog in Jaguar Manager, use java:comp/env/ejb/catalog in your JSP or servlet source code.

Steps To add an EJB reference:

  1. Display the EJB References tab in the Web Application Properties dialog box.

  2. Click Add. A reference with default settings is created. Edit the settings as described below.


Steps To edit an EJB reference:

  1. If necessary, display the EJB References tab in the Web Application Properties dialog box. Existing references are displayed as a list with one row for each reference.

  2. Edit the reference fields of interest as follows:

  3. To delete a reference, click anywhere in the fields for the reference of interest and click Delete.


Resource references

Resource references are used to obtain database connections and JavaMail sessions.

Steps To add a resource reference:

  1. Display the Resource References tab in the Web Application Properties dialog box.

  2. Click Add. A reference with default settings is created. Edit the settings as described below.


Steps To edit a resource reference:

  1. If necessary, display the Resource References tab in the Web Application Properties dialog box. Existing references are displayed as a list with one row for each reference.

  2. Edit the reference fields of interest as follows:

  3. Specify deployment properties:


Environment properties

Environment properties allow you to specify global read-only data for use by servlets and JSPs in the Web application.

Servlets and JSPs must use JNDI to retrieve environment properties, using the prefix java:comp/env in JNDI lookups. Unlike context initialization properties, environment properties can have datatypes other than java.lang.String.

The deployment descriptor catalogs the environment properties used by your servlets and JSPs, as well as each property's Java datatype and default value. Deployers can tailor the values to match a server's configuration. For example, you may have environment properties to specify the name of a logging file, or to tune cache usage.

Steps To add an environment property:

  1. Display the Environment tab in the Web Application Properties dialog box.

  2. Click Add. Jaguar Manager creates a new entry with default setttings. Edit the settings as described below:


Steps To edit environment properties:

  1. If necessary, display the Environment tab in the Web Application Properties dialog box. A list of environment properties appears.

  2. Edit the fields for the property of interest:


Request path mappings

Your application's deployment descriptor must specify the request path mappings for the application's servlets and JSPs. You can map full paths, partial paths, or file extensions to servlets. Path mappings are specified relative to the application's root request path.

To map request paths to a JSP, the JSP must be defined in Jaguar Manager as a Web component. See Chapter 24, "JavaServer Pages" for more information.

Jaguar uses the precedence rules defined in the Servlet 2.2 specification to evaluate each URL:

  1. Jaguar checks whether a mapping uses the exact path.
  2. Jaguar checks whether a directory in the path is mapped to a servlet, starting at the most deeply nested directory in the path, and working back using the forward-slash character (/) as a separator. For example, if the application's root request path is MyApp and the URL path is MyApp/Accounts/Manage/add.jsp, Jaguar checks for servlets mapped to /Accounts/Manage, then /Accounts.
  3. If the last node in the path contains an extension, Jaguar checks for a servlet mapped to that file extension. A file extension is defined as the part of the URL that follows a '.' occuring after the last '/' in the URL. For example, in the path MyApp/Accounts/Manage/add.calc, the extension is calc.
  4. If neither of the previous two rules results in a match, Jaguar invokes the application's default servlet if defined. The default servlet is mapped to the path /. If no default servlet is defined, Jaguar looks for a static file matching the path.

Note   Implicit JSP mapping The jsp extension is implicitly mapped to invoke Jaguar's JSP engine. You can override this mapping in the explicit mappings for your Web application.

Steps To add a request path mapping:

  1. Display the Servlet Mapping tab in the Web Application Properties dialog box.

  2. Click Add. A new mapping appears with default settings. Edit the settings as described below.


Steps To edit a request path mapping:

  1. If necessary, display the Servlet Name tab in the Web Application Properties dialog box. A list of mappings appears, formatted as a table. You can edit any mapping by editing the text directly within the table cells.

  2. Edit the servlet name and mapped path, using the following rules to format the path specification:


MIME mappings

A file's MIME type specifies how a server or browser should interpret the file. For example, whether the file contains plain text, formatted HTML, an image, or a sound recording. In a Web server, MIME mappings specify how a static file should be interpreted by mapping file extensions to MIME types. MIME mappings affect only static files. Servlets and JSPs must be coded to specify a MIME type for their response.

For more information on MIME types, visit:

http://www.oac.uci.edu/indiv/ehood/MIME/MIME.html

Jaguar includes preconfigured MIME mappings that you can customize using your Web application's properties. Web application MIME mappings override Jaguar's preconfigured mappings.

Steps To add a MIME mapping:

  1. Display the MIME Mapping tab in the Web Application Properties dialog box.

  2. Click Add.


Steps To edit a MIME mapping:

  1. If necessary, display the MIME Mapping tab in the Web Application Properties dialog box. The configured mappings display.

  2. Edit the fields as appropriate:


Security properties

Chapter 25, "Configuring Web Application Security" describes how to configure security for your Web application.

 


Copyright © 2000 Sybase, Inc. All rights reserved.