Chapter 22 Creating Web Applications
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.
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:
General properties are as follows:
com.sybase.jaguar.servlet.init.timeout
property
to the desired number of seconds.com.sybase.jaguar.servlet.destroy.wait-time
property
to the desired number of seconds.http://host:port/estore/
com.sybase.jaguar.webapplication.cookie.persistence
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.
To configure context initialization properties:
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 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.
To add a welcome file:
To delete a welcome file:
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.
To add an error page:
/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
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.
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.
Configuring TLD mappings in Jaguar Manager
com.sybase.jaguar.webapplication.taglib
.
Otherwise, modify the existing value for this property.(taglib-uri=alias, taglib-location=real-path)
(taglib-uri=taglib.tld, taglib-location=TLD/abctaglib.tld),
(taglib-uri=lib2.tld,taglib-location=TLD/lib2v2.tld)
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:
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.
To add an EJB reference:
To edit an EJB reference:
ejb/
.
For example, if your code refers to java:comp/env/ejb/MyBean,
enter ejb/MyBean
.com.sybase.MyBeanHome
.com.sybase.MyBeanRemote
.Resource references are used to obtain database connections and JavaMail sessions.
To add a resource reference:
To edit a resource reference:
jdbc/MyDatabase
.http://www.sybase.com
or ftp://pub.sybase.com
.
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.
To add an environment property:
To edit environment properties:
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:
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.
To add a request path mapping:
To edit a request path mapping:
/foo/*
or /foo/stuff/*
.
*.ext
,
where ext is the extension.
/
).
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.
To add a MIME mapping:
To edit a MIME mapping:
text/plain
or text/sgml
.
Chapter 25, "Configuring Web Application Security" describes how to configure security for your Web application.
Copyright © 2000 Sybase, Inc. All rights reserved. |