Cloud: Java Cloud Service SDK

#

## Sample Introduction

This sample is a simple JSP page example. It allows you to choose an English string representation of a locale from all the locales available to the Java platform, and then outputs a date localized for that locale. To ensure that the characters in the date can be rendered correctly for a wide variety of character sets, the JSP page that generates the date sets the response encoding to UTF-8.

The sample main JSP page `index.jsp` is a typical mixture of static HTML markup and JSP elements, it contains the following types of JSP constructs:

- A page directive (<%@page ... %>) sets the content type returned by the page.
- Tag library directives (<%@taglib ... %>) import custom tag libraries.
- jsp:useBean is a standard element that creates an object containing a collection of locales and initializes an identifier that points to that object.
- SP expression language expressions (${ }) retrieve the value of object properties. The values are used to set custom tag attribute values and create dynamic content.
- Custom tags set a variable (c:set), iterate over a collection of locale names (c:forEach), and conditionally insert HTML text into the response (c:if, c:choose, c:when, c:otherwise).
- jsp:setProperty is another standard element that sets the value of an object property.
- A function (f:equals) tests the equality of an attribute and the current item of a collection.

In addition, this sample defines a function `equals` using the same mechanisms as custom tags that can be invoked in an expression from the `index.jsp` page.

After you run the sample, a "Welcome" web page will be displayed with a form that allows you to select a locale and displays the date in a manner appropriate to the locale.

For details about the sample code, see the files that are listed in the following table.

## Main Files Used in the Sample

Directory Location:

SDK_HOME/samples/date

(where SDK_HOME is the directory containing your Java Cloud Service installation)

File Click source files to view code. | Description
--- | ---
build.xml | Ant build file that contains targets for building, deploying, and running the sample.
index.jsp | JavaServer page containing text-base markup and jstl components as the sample welcome page.
MyDate.java | Java class that returns the current date in format of the selected locale.
MyLocales.java | Java class that defines a public static method implementing the function of testing the equality of two strings.
web.xml | Web application deployment descriptor.
weblogic.xml | Oracle WebLogic Server-specific web application deployment descriptor.
functions.tld | JavaServer page containing the input user name and showing it as the response page.

## Prepare the Sample

### Prerequisites for Deploying the Sample Locally

1. Install WebLogic Server and configure it. This is required only if you want to deploy applications locally.
2. In the `SDK_HOME/samples/myenv.*` script, set the MW_HOME environment variable to the directory where WebLogic Server is installed.
3. Run the script:
   - On Linux, run: `. ./myenv.sh`
   - On Windows, run: `myenv.cmd`
4. Set the following environment variables in the `SDK_HOME/samples/build.common.properties` properties file:
   - set local to true, the default value is false.
   - set identity-domain to the identity domain name you deploy the application.
   - set service-instance to the service instance name you deploy the application.
   - set local-admin-url to the URL of the local WebLogic admin server.
   - set local-admin-user to the admin user who has permission to deploy the application.

You can also refer to Preparing Applications for Java Cloud Service Deployment in Using Oracle Java Cloud Service and the sample main page for more details.

### Prerequisites for Deploying the Sample on Java Cloud Service

If you are going to install your application only on a remote Java Cloud Service instance, you will not need to have WebLogic Server installed locally. Just make sure that "ant" and "javac" are available in the path.

Set the following environment variables in the `SDK_HOME/samples/build.common.properties` properties file:

- set identity-domain to the identity domain name you deploy the application.
- set service-instance to the service instance name you deploy the application.
- set cloud-admin-url to the admin URL that is used to deploy the application on Oracle Cloud.
- set cloud-admin-user to the admin user who has permission to deploy the application on Oracle Cloud.

## Build and Deploy the Sample

To build the sample, follow these steps:

1. Change to the `SDK_HOME/samples/date` directory, where SDK_HOME refers to the main Java Cloud Service SDK installation directory, such as `/home/user/oracle-javacloud-sdk`.
2. Execute the following command in the shell. (If you deploy the sample to local environment, choose the shell where you run the `myenv.*` script.)
   `ant clean`
   This command cleans the build directory.
   `ant build`
   This command compiles and stages the sample.
3. Execute the following command in the shell. (If you deploy the sample to local environment, choose the shell where you run the `myenv.*` script.)
   `ant install`
   This command installs the sample on the local WebLogic Server or a remote Java Cloud Service instance.

The Ant command uses the `build.xml` file in the `SDK_HOME/samples/date` directory to build the sample.

## Run the Sample

1. Complete the steps in the "Prepare the Sample" section.
2. Execute the following command in the shell. (If you deploy the sample to local environment, choose the shell where you run the `myenv.*` script.)
   `ant run`
   This command tries to automatically launch the web browser with the URL pattern `http://server:port/date`, where the server would include the identity domain and service instance name. For example, `https://java1-wnctrial.java.dc1.c9labga.us.oracle.com/date`, where `java1` is the service instance name and `wnctrial` is the identity domain. The rest of the host name `java.dc1.c9labga.us.oracle.com` is based on the environment. The actual URL should be printed when you run the samples.
   If the above does not work, you can open a browser, then copy and paste the above URL.
   For non-Windows and non-Mac machines, make sure that you have specified valid browser for the property `default.browser` in `SDK_HOME/samples/build.common.properties.`