Java EE 6 SDK

# The Cluster JSP Sample Application.

The cluster JSP sample application demonstrates how a request to a JSP is shared in all of server instances in a GlassFish cluster.

## Building and Deploying the Application

Perform the following steps to build, and deploy the application:

1. Setup your build environment and configure the application server with which the build system has to work by following the common build instructions.
2. `app_dir` is the sample application base directory: `samples_install_dir/javaee6/ha/clusterjsp`.
3. ````Change directory to `app_dir.`
4. Setup the server environment, build, and deploy the sample application using the `all` target.``

`app_dir> ant all`

You can replace the `ant all` command with the following set of commands:

`app_dir> ant setup` creates and starts a cluster with two instances

`app_dir> ant default` compiles and packages the application

`app_dir> ant deploy` deploys it to application server

Note: The `deploy` target will eventually display the URLs of the two instances as follow:

> `[echo] Application Deployed at: http://localhost:28082/clusterjsp and http://localhost:28083/clusterjsp`

Remember the port numbers, for instance in this example `Instance1HTTPPort=20802` and `Instance2HTTPPort=28083`

5. Use the target `undeploy` to undeploy the application.

   `app_dir> ant undeploy`

6. Use the target `unsetup` to stop and delete the cluster and its two instances.

   `app_dir> ant unsetup`

7. Use the target `clean` to remove the temporary directories like build and dist.

   `app_dir> ant clean`

## Running the Sample Application

The objective of this run is to demonstrate clustering and replication of session information across instances in a cluster. We achieve this by doing the following

1. Access the clusterjsp application through instance1 by launching a web browser and entering the URL http://<hostname>:<Instance1HTTPPort>/clusterjsp
2. Add session data by entering the session attribute name and value and clicking 'ADD SESSION DATA' button in the web page.
3. Stop instance1 using the `stop-instance1` target.

`app_dir> ant stop-instance1`

4. Access the clusterjsp application through instance2 by entering the URL http://<hostname>:<Instance1HTTPPort>/clusterjsp on the same browser window opened in step 1.
5. Verify that the session data generated from the application accessed through instance1 is automatically persisted and is visible when the application is accessed through instance2 of the cluster. You will be able to see the session attribute name and values persisted from instance1.

Please see the image below for a sample output of running steps 1 and 2 from above.

Please see the image below for a sample output of running steps 4 and 5 from above.

Copyright © 1997-2010 Oracle and/or its affiliates. All rights reserved.