Chapter 19 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 EAServer, most properties are automatically set during the import process.
Displaying 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.
Configuring 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 EAServer does not support directory listings.
Adding a welcome file
Deleting 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, the 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, EAServer checks if AException is mapped. If not, EAServer checks if BException is mapped, and so forth.
Adding an error page
/etc/error404.html
corresponds
to this file in your EAServer 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, EAServer 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 JavaBeans Clients" 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 JNDI 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 or configure an EJB reference, open the Web Application Properties dialog box.
The EJB References tab configuration is the same for
Web applications, application clients, and EJB components.
Adding an EJB reference
Editing 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
.To access an EJB's local interface, define an EJB local reference. Local interfaces are available only to EJB components, Java servlets, and JSPs hosted on the same server as the target component.
Adding an EJB local reference
Editing an EJB local reference
ejb/
.
For example, if your code refers to java:comp/env/ejb/MyBean,
enter ejb/MyBeanLocal
.com.sybase.MyBeanLocalHome
.com.sybase.MyBeanLocal
.Resource references are used to obtain connector and database connections, and to access JMS connection factories, JavaMail sessions, and URL links.
To add or configure a resource reference, open the Web Application Properties dialog box.
The Resource References tab configuration is the same
for Web applications, application clients, and EJB components.
Adding a resource reference
Editing a resource reference
jdbc/MyDatabase
. This is available only to Web applications and EJB components.
http://www.sybase.com
or ftp://pub.sybase.com
.
Resource environment references are logical names applied to objects administered by EAServer, which can be accessed by Web applications, application clients, and EJB components.
To add or configure a resource environment reference, open the Web Application Properties dialog box.
The Resource Environment References tab configuration
is the same for Web applications, application clients, and EJB components.
Adding a resource environment
reference
Editing a resource environment
reference
jms/MyQueue
.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 or configure an environment property, open the Web Application Properties dialog box.
The Environment tab configuration is the same for Web
applications, application clients, and EJB components.
Adding an environment
property
Editing an environment
property
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 22, "Creating JavaServer Pages" for more information.
EAServer uses the precedence rules defined in the Servlet 2.3 specification to evaluate each URL:
Implicit JSP mapping
The jsp extension is implicitly mapped
to invoke EAServer's JSP engine. You can override this
mapping in the explicit mappings for your Web application by mapping *.jsp to
a servlet or JSP. However, if you do so, there is no way to invoke
the EAServer JSP engine to compile and run arbitrary JSP files.
Explicit *.jsp mappings are not recommended.
Adding a request path mapping
Editing 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
EAServer includes preconfigured MIME mappings that you can customize using your Web application's properties. Web application MIME mappings override EAServer's preconfigured mappings.
Adding a MIME mapping
Editing a MIME mapping
Configures the default JAXP, DOM, and XSLT parser implementations used by the Web application. See Chapter 27, "Configuring Java XML Parser Support"for more information on these properties.
The Java Classes tab allows you to add classes and JAR files to the Web application's custom class list. The custom class list specifies which Java classes must be reloaded when the Web application is refreshed. Chapter 28, "Configuring Custom Java Class Lists" describes how to configure this setting.
The Extensions tab in the Web Application properties dialog box configures dependencies on Java extensions. These settings provide a mechanism to formally declare the Java extensions required by the Web application, and to verify that required extensions are available in EAServer. "Using Java extensions" describes these settings in detail.
The Additional Files tab in the Web Application properties
dialog box configures the com.sybase.jaguar.webapplication.files
property, which
specifies additional files that are to be archived when the Web application
is exported or replicated to another server with the synchronize feature.
By default, the file set includes the Web application's
context root directory and its contents.
The rules for setting this property are the same as for the com.sybase.jaguar.component.files component property. See "Component properties: Additional Files" for more information.
Configures user authentication for the Web application and allows you to configure authorized access to URLs served by the Web application. The EAServer Security Administration and Programming guide describes how to configure security for your Web application.
You can configure page caching for a Web application, as well as for a Web component. EAServer first checks the component-level page caching properties, and if none exists, checks the application-level properties. "Page caching" describes how to configure page caching for a Web component.
Configuring page caching for a Web application
By default, page caching is disabled, and you cannot
enable page caching at the Web application-level.
EAServer's implementation of application lifecycle events enables you to register event listeners that can respond to state changes in a Web application's ServletContext and HttpSession objects. See "Application lifecycle event listeners" for more information.
Adding a listener
A filter is a Java class that is called to process client requests or the server's response. Filters can be used to modify the request header or the content of a servlet request or response. Chapter 21, "Using Filters and Event Listeners" describes how to create filters.
Filters can be mapped to a URL or a servlet name. When a filter is mapped to a URL (path-mapped), the filter applies to every servlet and JSP in the Web application. When a filter is mapped to a servlet name (servlet-mapped), it applies to a single servlet or JSP. The path-mapped filters are executed first, followed by the servlet-mapped filters.
Mapping a filter
Copyright © 2002 Sybase, Inc. All rights reserved. |
![]() |