Chapter 22 Creating Web Applications


Contents of a Web application

Web applications contain the following components.

Servlet files

Servlets are Java classes that create HTML pages with dynamic content and respond to requests from client applications that are implemented as HTML forms. Servlets also allow you to execute business logic from a Web browser or any other client application that connects using the Hypertext Transfer Protocol (HTTP). For more information on creating servlets, see Chapter 23, "Creating Java Servlets".

Web clients invoke your Web application's servlets by prepending the Web application's root request path to an alias that is mapped to the servlet. For example, the following URL invokes a servlet mapped to the alias "Account" in the application with root request path "Finance":

http://myhost/Finance/Account?type=add

JSP files and tag libraries

JavaServer Pages (JSP) allow you to embed snippets of Java code into HTML pages to create dynamic content. JSP tag libraries allow you to extend the standard HTML markup tags with custom tags backed by Java classes. See Chapter 24, "JavaServer Pages" for more information on creating JSPs.

Static files

Files that provide static content for the site can be included in the Web site, including HTML, images, sounds, and so forth. You can also include Java applet files. You can configure the application's deployment descriptor to specify security constraints for static files and any unique MIME types required by your content.

Static files must be deployed to the following subdirectory in your Jaguar installation directory:

Repository/WebApplication/web-app

Where web-app is the name of the Web application. You can include subdirectories, which are reflected in your application's URL namespace.

If you import a Web archive (WAR) file, the importer expands the application's static files to this location.

Java classes

A Web application's Java classes include the implementation class for each servlet and JSP, and any server-side utility classes used by the servlets and JSPs.

Jaguar uses a custom class loader to run a Web application's servlets and classes referenced by servlet and JSP code. This feature allows hot refresh of servlets and JSPs. The custom class loader also allows each Web application to run with its own effective Java class path. To work with the custom loader and support hot refresh, you must deploy your Web application classes as described below.

Class file locations

You can deploy class files in the following locations, where app_name is the name of the Web application:

Which classes are loaded by the custom loader?

In order to allow hot refresh, class references in your servlet and JSP code must be resolved by Jaguar's custom class loader.

Note   Classes loaded by the system class loader Class instances loaded by the system class loader cannot be refreshed. Class instances loaded by the custom class loader cannot be assigned to references loaded by the system class loader, or vice-versa.

Most all references will be resolved by the custom loader. The exceptions are references made with class loader calls with an explicit reference to the system class loader or another custom class loader. The following class references are all resolved by the custom class loader when they occur in servlet code:

Code that uses the system class loader should be rewritten to use the servlet class loader when possible. The system class loader cannot load classes from the Web application WEB-INF/classes or WEB-INF/lib directories unless you add these locations to the server BOOTCLASSPATH and CLASSPATH environment variables. Classes loaded by the system class loader cannot be refreshed while the server is running.

Extending the custom class list

Your Web application may use classes or JAR files that are used by Java clients and components. These files can be deployed in the Jaguar java/classes or html/classes subdirectories. Classes and JAR files loaded from these locations can not be refreshed unless listed in the value of the Web application's com.sybase.jaguar.webapplication.java.classes property, or the servlet or JSP's com.sybase.jaguar.servlet.java.classes property. Configure these properties on the All Properties tab of the Web Application Properties or Web Component Properties dialog box, respectively.

When setting the com.sybase.jaguar.servlet.java.classes and com.sybase.jaguar.webapplication.java.classes property, enter any of the following separated by commas:

Class file search order

The custom class loader loads Web application classes by searching the following code bases, in the order specified. All of these locations are subdirectories of your Jaguar installation directory, app_name represents the name of your Web application, and server is the server where the Web application is installed. If the custom class loader cannot locate a class file, Jaguar attempts to load it using the system class loader.

  1. work/server/Servlet/WebApp-app_name (a JSPs generated servlet class)
  2. Repository/WebApplication/app_name/WEB-INF/lib (for JAR files only)
  3. Repository/WebApplication/app_name/WEB-INF/classes (for class files only)
  4. JAR files in the java/classes and html/classes directory that are specified in the servlet or JSPs com.sybase.jaguar.servlet.java.classes property or the Web application's com.sybase.jaguar.webapplication.java.classes property.
  5. Class files in the java/classes and html/classes directory that are specified in the servlet or JSPs com.sybase.jaguar.servlet.java.classes property or the Web application's com.sybase.jaguar.webapplication.java.classes property.
  6. If the class has not been found, Jaguar attempts to load the class using the system class loader, which searches directories and JAR files listed in the Jaguar server's CLASSPATH environment variable.

Deployment descriptor

The application's deployment descriptor catalogs the servlets, JSPs, and files contained in the application, as well as the properties of each. The descriptor must be formatted in XML, using the DTD specified in the Java Servlet Specification Version 2.2. You can create a descriptor using Jaguar Manager or another J2EE-compliant development tool.

 


Copyright © 2000 Sybase, Inc. All rights reserved.