Sun Java System logo     
Caching Web Sample Application



Caching Web Sample Application


This document describes how to utilize the Caching Web sample application in conjunction with Sun Java (tm) System Application Server 7.

This sample application document contains the following sections:



Overview

The Caching Web sample application demonstrates how to utilize servlet/JSP caching on the Sun Java (tm) System application server. Sun Java (tm) System Application Server provides value-added services that enable results caching at both the JSP and Servlet level. Using results caching enables you to increase server performance by allowing subsequent calls to JSPs and Servlets to be returned using cached results instead of reinvoking Java code to generate the resulting content from scratch.

The servlet caching sample demonstrates how servlet caching can be controlled using deployment descriptors(sun-web.xml). The cache on/off, time-outs can be adjusted at deployment time without any coding changes content from scratch.

The JSP caching sample shows how JSP caching can be achieved by utilizing JSP tags. The cache on/off, cache time-out can be controlled by the aattribute value of the JSP tag.

To better understand sample application source code, you may refer to the related javadocs which can be accessed at sjsas_install_dir/samples/webapps/caching/javadocs/index.html after it is generated.



Compiling and Assembling the Application



This section contains instructions to compile and assemble the Caching Web sample application.

  1. Go to sjsas_install_dir/samples/webapps/caching/src/

    Execute the command asant



    Note You must add sjsas_install_dir/bin to your path.



    The default target core will be executed to build the WAR file.

  2. Deploy the application.

    After you have re-created the sample application from scratch, you may proceed to Deploying the Sample Application. Step 3 is optional.

  3. Clean the web application project area (optional).

    Execute the command asant clean to clean the web application.



Deploying the Sample Application

In this section, you will learn how to deploy the Caching Web sample application.

Deploying the pre-built webapps-caching.war file is simple. you may deploy by either Using the asant script or by Using the asadmin command.


Using the asant script

  1. Go to the src directory of the sample. For example:

    sjsas_install_dir/samples/webapps/caching/src

  2. Run asant using deploy task. For example:

    %asant deploy


Using the asadmin command

  1. Go to sjsas_install_dir/samples/webapps/caching/

  2. Execute the following:

    asadmin deploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> --type web webapps-caching.war

The deployment process involves the following operations:

  • Authenticates against the local application server's administrative server

  • The WAR file is transferred to the administrative server

  • The administrative server begins the registration process:

    • Parses the WAR file

    • Explodes the bits into repository

    • Registers the J2EE module "webapps-caching" by updating server.xml

If you would like to verify the registration of the application, you may proceed to Verifying Deployment. Otherwise, proceed to Running the Sample Application.


Verifying Deployment

As an optional step, you can use the Sun Java (tm) System Application Server Administration Tool to verify that the application has been registered. Otherwise, proceed directly to Running the Sample Application.

To verify the registration of the application, do the following:

Execute the command asadmin to look at applications deployed with a server instance. For example:

asadmin list-components -u <username> -w <password> -H <host> -p <admin-port> --type web <server instance name>

You will see the webapps-caching module displayed as one of the listed components.


Undeploy the application

If you wish to undeploy the application after successful deployment, you may do so by either Using the asant script or by Using the asadmin command.


Using the asant script

  1. Go to sjsas_install_dir/samples/webapps/caching/src

  2. Execute the following:

    asant undeploy


Using the asadmin command

  1. Go to sjsas_install_dir/samples/webapps/caching/src

  2. Execute the following:

    asadmin undeploy -u <user-name> -w <password> -H <hostname> -p <admin server port> --instance <instance name> --type web webapps-caching



Running the Sample Application

You may run the appliction through the following URL:

http://<AppServer hostname>:<port>/webapps-caching/index.html

Servlet Caching: Based on the sun-web.xml, the results are cache'ed if the Input String is either "one" or "two" no matter the Delivery Mechanism is "Servlet Only" or "Via JSP". If you like to turn the cache off or change the cache time-out value , you can achieve it by modifying the attributes of the cache element in sun-web.xml.


Troubleshooting



If you encounter problems when running the application, review the log files at sjsas_install_dir/domains/<domain-instance> /<server-instance>/logs/server.log to learn what exactly went wrong.



Copyright © 2002 Sun Microsystems, Inc. All rights reserved.

Last Updated July 18, 2002