Oracle Internet File System Developer's Guide Release 1.1 A75172-04 |
Library | Service | Contents | Index

# 7
Using JSPs

This chapter covers the following topics:

- Using Java Server Pages to Display Documents

- Implementing an Application Using a JSP

- Running the Sample Insurance Form Application

- Sample Files for the Insurance Form Application

Note: Do not confuse Java Server Pages, commonly known as "JSPs," with the Oracle Corporation product called Java Stored Procedures. In the context of this chapter, "JSPs" refers to "Java Server Pages."

## Using Java Server Pages to Display Documents

One of the advantages of storing documents in the Oracle Internet File System is that users can display dynamic data via the Web simply by entering a URL. For example, in an insurance form application, a user would be able to view an insurance form on the Web.

Java Server Pages (JSPs) are the recommended manner of creating web-based applications based on Oracle iFS. (In fact, the Oracle iFS Web interface uses JSPs.) JSPs display information on the Web by generating HTML documents to call Java Beans. Although JSPs provide a way for users to view and manipulate documents, providing a functionality parallel to that of renderers, using a JSP is not technically "rendering" because it does not involve calling a specific renderer.

Note: You can use either the Java Web Server or the Apache Web Server with Oracle iFS. The Java Web Server included with Oracle iFS 1.1 supports the 1.0 version of the JSP specification. Developers are advised to avoid the use of tag extensions defined by the 0.92 specification.

### Preparing to Use JSPs

An insurance form application is used to demonstrate how to use JSPs. Assume that the following preparations have been completed so that there are custom InsuranceForm objects stored in the repository, ready to be displayed using a JSP:

1. Using XML, create a type definition file, CreateInsuranceForm.xml, to define the custom attributes of the insurance form. (Creating this type definition file in XML is the equivalent of subclassing the Document class in Java.)

2. Using Java, create an instance class Bean, InsuranceFormObject.java, to provide standard getter and setter methods for the custom attributes defined in the type file. (This step is recommended, but not required. The instance class Bean file is shown in Chapter 4, "Creating Custom Classes".)

3. Using XML, create the actual insurance form documents, claim1.xml and claim2.xml, each one created as an instance of the InsuranceForm class. Load the document instance files into Oracle iFS using either the Web interface or the Windows interface. The insurance forms will be parsed automatically by the SimpleXmlParser.

## Implementing an Application Using a JSP

An application that uses a JSP to display information consists of four components:

Component | Purpose | Files/Utility Needed | Example
--- | --- | --- | ---
Login files | Authenticate the user. | Login JSP Corresponding Java Bean | ``Sample Code: login.jsp``

``Sample Code: InsuranceLogin.java`
`

Logout files

Close the session.

Logout JSP

``Sample Code: logout.jsp`
`

Application files

Display information stored in Oracle iFS using the Web.

Application JSP

Corresponding Java Bean

``Sample Code: InsuranceForm.jsp``

``Sample Code: InsuranceBean.java``

Registration using Oracle iFS Manager

Connect a document type with the JSP used to display it.

Oracle iFS Manager

``Registering a Java Server Page Using Oracle iFS Manager``

### Login/Logout Files

Each application requires a set of files to provide basic security functions:

- User Login and Validation

- User Logout

The sample code for these functions, login.jsp and logout.jsp, provides a reliable starting point for a login/logout mechanism.

For consistent behavior with multiple protocols and sharing login information with the Oracle iFS Web interface, we recommend using the basic approach to login/logout demonstrated in the sample code. Specifically, we recommend that when writing a JSP login facility, you implement the Oracle iFS Java API package `oracle.ifs.adk.security.IfsHttpLogin.`

#### User Login and Validation

For an example of a login JSP and its associated Java Bean, see:

- "Sample Code: login.jsp"

- "Sample Code: InsuranceLogin.java"

  InsuranceLogin.java implements the public interface `IfsHttpLogin`.

These sample applications store the minimum login and session information needed by the system to carry user authentication from page to page. Depending on the requirements of your application, you may decide to create a more complex login to store user variables or more extensive session information.

#### User Logout

For an example of a simple logout JSP, see "Sample Code: logout.jsp".

### Application Files

The real work of an application is done by one or more JSPs and their corresponding Java Beans:

- The JSP calls the Java Bean and creates an HTML page to display the information from the database.

  For a sample JSP file, see "Sample Code: InsuranceForm.jsp". This sample shows a simple user interface; your application may require a more sophisticated user interface.

- The Java Bean retrieves and manipulates information from the database. The Java Bean contains the business application logic. For example, if your application requires that all invoices with a total greater than $10,000 be approved by a specific manager, that logic would go in the Java Bean.

  For a sample Java Bean file, see "Sample Code: InsuranceBean.java".

#### Compiling Java Beans and JSPs

You must compile the Java Bean and then the JSP before Oracle iFS can call the JSP. Depending on your development environment, the JSP may be automatically compiled at runtime the first time it is invoked.

#### Deploying Java Beans and JSPs

All compiled Java Beans must be stored in the directory `$ORACLE_HOME/ifs/custom_classes` on the server where Oracle iFS is installed.

The Oracle iFS product comes with a starting-point directory structure. One of the folders in that structure is reserved for holding JSPs: `$ORACLE_HOME/ifs/jsp-bin`. To have your JSP compile and execute properly in Oracle iFS, you must store the JSP in this folder. JSPs stored elsewhere will not be executed by the Oracle iFS JSP compiler.

### Registering a JSP

Registering a JSP allows the JSP to be used as the default HTML renderer for the specified class.When a user clicks on a plain XML document, the system automatically calls the SimpleXmlRenderer supplied with Oracle iFS. When a user clicks on a custom document for which you have provided a JSP, Oracle iFS needs to know which JSP to use to display documents of this type. To provide this information to Oracle iFS, you must register a JSP before it can be used.

You can use Oracle iFS Manager or XML to register a JSP. Once a JSP has been registered, Oracle iFS automatically invokes that JSP when a user requests a document of a given class and MIME type. Behind the scenes, registering a JSP adds an entry to the existing JSPlookup PropertyBundle, associating a JSP with a specific class and MIME type. For an example, see "Registering a Java Server Page Using Oracle iFS Manager".

Note: Using the Jsplookup PropertyBundle mechanism will meet the requirements of most applications. If your application has complicated requirements in this area, you are free to use a custom method to trigger the use of specific code when a user accesses custom documents.

#### The Jsplookup PropertyBundle

To associate a JSP with a specific class, Oracle iFS provides a lookup table mechanism called the "Jsplookup PropertyBundle." The Jsplookup PropertyBundle is automatically created during installation.

The Jsplookup PropertyBundle maps a specific class and MIME type to the corresponding JSP. In the best case, both document class and document MIME type are available. Depending on the specific document, however, sometimes only document class or MIME type are available. The Jsplookup PropertyBundle determines which JSP should be used with which class based on all available information about the class, assessed in this sequence:

1. Combination of document class and document MIME type.

2. Document class only.

3. Document MIME type only.

### Web Site Security Using HTTP Authentication

HTTP authentication is used to control access to web sites. For example:

- You may want to limit access to all of your web site.

- You may want only specific users to be able to access certain parts of the web site.

Assume, for example, that you have a web site with a "Members Only" section. You would want everyone to have access to the web site, but only people with a special password have access to the "Members Only" section.

The HTTP authentication mechanism causes the browser to pop up a dialog window. This dialog window accepts the following input from the user:

- User name

- Password

Once a valid value has been supplied, this user name/password information is kept with the current session, which allows this user access to all appropriate documents, based on the security provided by the associated ACLs. Note that this user's user name/password information is stored by the browser. Thus, if the user invokes additional instances of the browser, the authentication is also valid for these instances. Until the user exits from all instances of the browser, these access rights are not disabled. This behavior is browser-specific. For example, if a user authenticates using Netscape Communicator, that user does not need to authenticate for any more instances of Netscape Communicator, but will need to provide authentication for an instance of Internet Explorer.

In order to use HTTP authentication, you must substitute your own "index.html" for the default "index.html" in the root directory, so users will go to your web site rather than the Oracle iFS Web interface. When users log in through the Web interface, the Web interface authentication takes precedence over HTTP authentication.

### Implementing HTTP Authentication

Oracle iFS implements HTTP authentication using Access Control Lists (ACLs). Assume that you have a web site where you want to specify the following access for the "Members Only" section:

- Everyone should be able to see that the "Members Only" section exists.

- Read access to the "Members Only" section is restricted to specific users.

To access this restricted section, the user needs to click a "Members Only" button (`members.gif`) displayed on the Home page.

To implement HTTP authentication for this web site according the scenario described above, follow this process.

1. The default `index.html` file in the root (/) directory points to the Oracle iFS Web interface. As part of creating your web site, create a file called `index.html` and replace the `index.html` file in the root directory with the file that points to your web site.

2. As another part of creating your web site, create an HTML document to serve as the gateway to the "Members Only" section.

   This HTML page will serve as the HREF for `members.gif`.

3. Log in using an administration-enabled account, and create a new ACL to handle HTTP authorization.

   Assume this new ACL is named "HTTP_Auth." Assign the following rights:

   - Guest - Discover access only.

   - Qualified user - Read access.

4. Log in using an administration-enabled account, and apply the HTTP_Auth ACL to the `index.html` document created in Step 1.

5. Exit the browser.

Now when a user enters the web site and clicks the "Members Only" button, the authentication dialog will be displayed. If the user provides the correct user name and password, that user will gain access to the "Members Only" section.

## Running the Sample Insurance Form Application

The Insurance Form application includes three JSPs:

- "Sample Code: login.jsp" allows a user to log in to Oracle iFS.

- "Sample Code: logout.jsp" allows a user to log out of Oracle iFS.

- "Sample Code: InsuranceForm.jsp" provides the application logic.

Note: This example includes the recommended mechanism for providing a login facility to Oracle iFS, which is implementing the `IfsHttpLogin` interface.

For a brief description of each sample file, see "Sample Files for the Insurance Form Application".

### Create the Insurance Form Application

1. Create these directories:

   - `public/examples/insuranceApp`

   - `public/examples/insuranceApp/src`

   - `public/examples/insuranceApp/claims`

2. Compile these Java programs:

   - `InsuranceLogin.java`

   - `InsuranceBean.java`

   Place the folder tree containing the resulting `.class` file in the directory `$ORACLE_HOME/ifs/custom_classes` on the server where Oracle iFS is installed.

3. Use FTP to put the Java source code into `/public/examples/insuranceApp/src`.

4. Use FTP to put `index.html` into `/public/examples/insuranceApp`.

5. Use FTP to put `CreateInsuranceForm.xml` into any convenient directory.

6. Using Oracle iFS Manager, register the `InsuranceForm.jsp`.

7. Use FTP to put the following two document files representing claims into `/public/examples/insuranceApp/claims`:

   - `claim1.xml`

   - `claim2.xml`

8. Use FTP to put the three JSPs into `/ifs/jsp-bin`:

   - `login.jsp`

   - `logout.jsp`

   - `InsuranceForm.jsp`

### Run the Insurance Form Application

1. Start the Web Server.

2. Enter the following URL into your favorite web browser:

        http://myIfsServer/public/examples/insuranceApp/src/login.jsp

3. Log in to Oracle iFS.

4. To view the claims, log in and click on the claim files:

   - Juana Angeles

   - Kevin Chu

5. To logout, click on `logout.jsp`.

#### Requirements for Running the Examples

To run these examples, observe the following requirements:

- Compile all `.java` files.

- To compile, include the following .jar files in the `CLASSPATH` environment variable:

  - `repos.jar`

  - `adk.jar`

- Be sure the JSPs are stored in `/ifs/jsp-bin`.

## Sample Files for the Insurance Form Application

This section includes sample code for running the Insurance Form application. The files included are:

Name | Description
--- | ---
`index.html` | An HTML file that is automatically invoked when a user's URL navigates to a folder.
`CreateInsuranceForm.xml` | An XML file that creates a custom document type (a subclass of the Document class).
`claim1.xml claim2.xml` | Two XML insurance claim files that create instances of the InsuranceForm class.
`login.jsp` | A JSP to allow user login and validation. Calls `InsuranceLogin.java.`
`InsuranceLogin.java` | A Java Bean called by `login.jsp.`
`logout.jsp` | A JSP to allow user logout.
`RegisterJSP.xml` | An XML file to register a JSP, thus associating the JSP with a specific class and MIME type. Alternatively, you can use Oracle iFS Manager to register a JSP.
`InsuranceForm.jsp` | A JSP to display application information retrieved by `InsuranceBean.java`.
`InsuranceBean.java` | A Java Bean called by `InsuranceForm.jsp` to retrieve attributes of a specific insurance form.

### Sample Code: index.html

This `index.html` file is automatically invoked when a user, using a URL, navigates to the folder where this file resides.

    <HTML>
    <!-- index.html -->
    <HEAD>
    <META HTTP-EQUIV=REFRESH CONTENT="0;
      URL=/public/examples/insuranceApp/src/login.jsp">
    </META>
    </HEAD>
    <BODY>
    </BODY>
    </HTML>

### Sample Code: CreateInsuranceForm.xml

This `CreateInsuranceForm.xml` file creates a custom document type with two custom attributes, ClaimNumber and ClaimType.

    <?xml version = '1.0' standalone = 'yes'?>
    <!-- CreateInsuranceForm.xml -->
    <ClassObject>
       <Name>InsuranceForm</Name>
       <Superclass Reftype ="name">Document</Superclass>
       <Attributes>
          <Attribute>
              <Name>ClaimNumber</Name>
              <DataType>Long</DataType>
          </Attribute>
          <Attribute>
              <Name>ClaimType</Name>
              <DataType>String</DataType>
              <DataLength>50</DataLength>
          </Attribute>
       </Attributes>
    </ClassObject>

### Sample Code: claim1.xml, claim2.xml

These two files, `claim1.xml` and `claim2.xml`, are the document files that create two specific instances of the InsuranceForm class.

    <?xml version = '1.0' standalone = 'yes'?>
    <!-- claim1.xml -->
    <InsuranceForm>
       <Name>Juana Angeles</Name>
       <ClaimNumber>35093</ClaimNumber>
       <ClaimType>Car Accident</ClaimType>
       <FolderPath>/public/examples/insuranceApp/claims</FolderPath>
    </InsuranceForm>

    <?xml version = '1.0' standalone = 'yes'?>
    <!-- claim2.xml -->
    <InsuranceForm>
       <Name>Kevin Chu</Name>
       <ClaimNumber>41111</ClaimNumber>
       <ClaimType>Car Accident</ClaimType>
       <FolderPath>/public/examples/insuranceApp/claims</FolderPath>
    </InsuranceForm>

### Sample Code: login.jsp

This `login.jsp` file is a JSP that provides for user login and validation. It calls the `InsuranceLogin.java` file. Note that "IfsHttpLogin" is the default login Bean name used for the Oracle iFS Web interface.

    <%@ page import = "ifsdevkit.sampleapps.insurance.InsuranceLogin" %>
    <%@ page import = "oracle.ifs.adk.security.IfsHttpLogin" %>

    <html><head>

    <jsp:useBean id="inslogin" scope="session"
    class="ifsdevkit.sampleapps.insurance.InsuranceLogin" />
    <jsp:setProperty name="inslogin" property="*"/>

    <%
      String REDIRECT_PATH = "/public/examples/insuranceApp/claims";
      boolean loggedIn = false;
      if (inslogin.getSession() != null && inslogin.getResolver() != null)
      {
        // Use existing insurance login
        loggedIn = true;
      }
      else
      {
        // No existing insurance login
        IfsHttpLogin login = (IfsHttpLogin)
    request.getSession(true).getValue("IfsHttpLogin");
        if (login != null && login.getSession() != null && login.getResolver() !=
    null)
        {
          // Use existing IfsHttpLogin login
          inslogin.init(login.getSession(), login.getResolver());
          loggedIn = true;
        }
      }
      if (!loggedIn)
      {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        if (username != null && password != null)
        {
          // Login using username/password
          try
          {
            inslogin.init(username, password, "IfsDefault");
            request.getSession(true).putValue("IfsHttpLogin", inslogin);
            loggedIn = true;
          }
          catch (Exception e)
          {
    %>
    <SCRIPT LANGUAGE="JavaScript1.2">
            alert("The username or Password was not valid, please try again.");
    </SCRIPT>
    <%
          }
        }
      }
      if (loggedIn)
      {
        // Redirect to the directory where the claim files reside
        response.sendRedirect(REDIRECT_PATH);
      }
      else
      {
    %>
    <title>Insurance Demo App Login</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF">
      <form METHOD=POST NAME="loginform" ACTION="login.jsp">
        <table>
          <tr>
            <td><b>Username:</b></td>
            <td><input type="text" name="username" value=""></td>
          </tr>
          <tr>
            <td><b>Password:</b></td>
            <td><input type="password" name="password" value=""></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>
              <input type="submit" value="Log in">
            </td>
            <td>
              <input type="reset" value="Reset">
            </td>
          </tr>
        </table>
      </form>
    </body>
    </html>

    <% } %>

### Sample Code: InsuranceLogin.java

This sample file, `InsuranceLogin.java`, creates the Java Bean that is called by `login.jsp`, the corresponding JSP. This Java Bean implements the standard Oracle iFS login interface, `IfsHttpLogin`.

    /* --InsuranceLogin.java-- */
    package ifsdevkit.sampleapps.insurance;

    import java.util.Locale;
    import javax.servlet.http.HttpSessionBindingEvent;
    import oracle.ifs.beans.DirectoryUser;
    import oracle.ifs.beans.FolderPathResolver;
    import oracle.ifs.beans.LibrarySession;
    import oracle.ifs.beans.LibraryService;
    import oracle.ifs.common.CleartextCredential;
    import oracle.ifs.common.ConnectOptions;
    import oracle.ifs.common.IfsException;
    import oracle.ifs.adk.security.IfsHttpLogin;

    /**
     * The login bean for the Insurance demo app.
     * <p>
     * This class provide the login info. The class implements the
     * <code>IfsHttpLogin</code> interface so it can share login data with other
     * login beans.
     *
     * @see IfsHttpLogin
     */

    public class InsuranceLogin implements IfsHttpLogin
    {
      /**
       * The <code>LibrarySession</code>.
       */
      private LibrarySession m_session;

      /**
       * The <code>FolderPathResolver</code>.
       */
      private FolderPathResolver m_resolver;

      /**
       * Default constructor required by the jsp spec for the USEBEAN tag
       *
       * @exception IfsException
       */
      public InsuranceLogin()
      throws IfsException
      {
      }

      /**
       * Make a connection to iFS
       *
       * @param username  The username to be used for login.
       *
       * @param password  The password to be used for login.
       *
       * @param server    The server to be used for login.
       *
       * @exception IfsException if operation failed.
       */
      public void init(String username, String password, String serviceName)
      throws IfsException
      {
        LibraryService service = new LibraryService();

        CleartextCredential me = new CleartextCredential(username, password);
        ConnectOptions connection = new ConnectOptions();
        connection.setLocale(Locale.getDefault());
        connection.setServiceName(serviceName);
        m_session = service.connect(me, connection);

        m_resolver = new FolderPathResolver(m_session);

        m_resolver.setRootFolder();

        DirectoryUser user = m_session.getDirectoryUser();
        if (user.isAdminEnabled())
          m_session.setAdministrationMode(true);
      }

      /**
       * Initialize the login bean.
       * <p>
       * The default constructor does not set the necessary fields so it needs
       * to be set instantiation.
       *
       * @param session   The <code>LibrarySession</code> object.
       *
       * @param resolver  The <code>FolderPathResolver</code> object.
       *
       */
      public void init(LibrarySession session, FolderPathResolver resolver)
      {
        m_session = session;
        m_resolver = resolver;
      }

      /**
       * Return the login's session object.
       *
       * @return The <code>LibrarySession</code> object.
       */
      public LibrarySession getSession()
      {
        return m_session;
      }

      /**
       * Return the login's path resolver.
       *
       * @return The <code>FolderPathResolver</code> object.
       */
      public FolderPathResolver getResolver()
      {
        return m_resolver;
      }

      /**
       * Called when this object is bound to the HTTP session object.
       *
       * @param event  The event when the object is bound to the Http session.
       */
      public void valueBound(HttpSessionBindingEvent event)
      {
        // do nothing
      }

      /**
       * Called when this object is unbound from the HTTP session object.
       *
       * @param event  The event when the object is unbound to the Http session.
       */
      public void valueUnbound(HttpSessionBindingEvent event)
      {
        m_resolver = null;
        try
        {
          if (m_session != null)
          {
            m_session.disconnect();
          }
        }
        catch (IfsException e)
        {
          e.printStackTrace();
        }
        finally
        {
          m_session = null;  // release the resources
        }
      }

    }

### Sample Code: logout.jsp

This sample file, `logout.jsp`, is a JSP that provides for user logout and a graceful exit from the program.

    <%@ page import = "ifsdevkit.sampleapps.insurance.InsuranceLogin" %>
    <%@ page import = "oracle.ifs.adk.security.IfsHttpLogin" %>

    <html><head>

    <%
      Object login = request.getSession(true).getValue("inslogin");
      if (login != null)
      {
        // Remove insurance login
        request.getSession(true).removeValue("inslogin");
        Object ifsLogin = request.getSession(true).getValue("IfsHttpLogin");
        if (ifsLogin != null && ifsLogin == login)
        { // Only remove IfsHttpLogin if it is the same login bean
          // Remove IfsHttpLogin login
          request.getSession(true).removeValue("IfsHttpLogin");
        }
      }
    %>
    <title>Insurance Demo App Logout</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#FFFFFF">
      <form METHOD=POST NAME="logout" ACTION="login.jsp">
        <table>
          <tr>
            <td><h3>You are now logged out.</h3></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td>
              <input type="submit" value="Log in">
            </td>
          </tr>
        </table>
      </form>
    </body>
    </html>

### Registering a Java Server Page Using Oracle iFS Manager

To register a Java Server Page using Oracle iFS Manager, follow these steps:

1. From the Oracle iFS Manager Object menu, choose Register.

2. From the Select Object Type window, choose Java Server Page (JSP) Lookup.

3. From the Java Server Page (JSP) Lookup Registry window, choose Add.

4. In the Java Server Page (JSP) Lookup Entry window, specify the attributes according the JSP Attributes table.

To register a JSP, specify the following three attributes:

Attribute | Description | Examples
--- | --- | ---
Classname | Name of the custom class that uses this JSP. Case-sensitive. | `INSURANCEFORM`
Mimetype | MIME type and subtype of files this JSP can render, in the format: `MyMIMEType1/MyMIMEType2` `MyMIMEType1` specifies a main MIME type, such as "text"; `MyMIMEType2` specifies a MIME subtype, such as "HTML". | `text/HTML video/quicktime` To specify that all MIME types can be rendered, use */*: `INSURANCEFORM.*/*`
JSP pathname | Location of the compiled JSP. | `/ifs/jsp-bin/InsuranceForm.jsp`

- Click OK.

  ### Registering a Java Server Page Using XML

  This sample file, `RegisterJSP.xml`, registers a JSP, associating the JSP with a specific classname and MIME type.

  To register a JSP using XML, write an XML file to update the JspLookup PropertyBundle, adding a mapping between a specific classname and MIME type (`INSURANCEFORM.*/*`) and its associated JSP (`InsuranceForm.jsp`).

      <?xml version="1.0" standalone="yes"?>
      <!--RegisterJSP.xml-->
      <PROPERTYBUNDLE>
         <UPDATE RefType="valuedefault">JspLookup</UPDATE>
         <PROPERTIES>
            <PROPERTY ACTION="add">
               <NAME>INSURANCEFORM.*/*</NAME>
               <VALUE DataType="String">/ifs/jsp-bin/InsuranceForm.jsp</VALUE>
            </PROPERTY>
         </PROPERTIES>
      </PROPERTYBUNDLE>

  ### Sample Code: InsuranceForm.jsp

  This sample file, `InsuranceForm.jsp`, includes the following:

  - HTML code to govern the display of the insurance form.

  - A call to the Java Bean `InsuranceBean.java`, which provides the information from the insurance form stored in the repository.

        <HTML>
        <!-- InsuranceForm.jsp-->
        <%@ page import="ifsdevkit.sampleapps.insurance.InsuranceBean" %>
        <%@ page import="oracle.ifs.beans.LibrarySession" %>
        <%@ page import="oracle.ifs.beans.FolderPathResolver" %>
        <%@ page import="oracle.ifs.adk.security.IfsHttpLogin" %>

        <jsp:useBean id="ibean" scope="session"
        class="ifsdevkit.sampleapps.insurance.InsuranceBean" />
        <jsp:useBean id="inslogin" scope="session"
        class="ifsdevkit.sampleapps.insurance.InsuranceLogin" />

        <HEAD>
            <TITLE>Oracle iFS</TITLE>
        </HEAD>
        <BODY>
        <%
          LibrarySession sess = null;
          FolderPathResolver resolver = null;
          if (inslogin != null && inslogin.getSession() != null &&
        inslogin.getResolver() != null)
          {
            sess = inslogin.getSession();
            resolver = inslogin.getResolver();
          }
          else // Not logged in the Insurance App but may be logged in other
        application.
          {
            IfsHttpLogin login =
        (IfsHttpLogin)request.getSession(true).getValue("IfsHttpLogin");
            if (login != null && login.getSession() != null && login.getResolver() !=
        null)
            {
              sess = login.getSession();
              resolver = login.getResolver();
            }
          }
          String path = request.getParameter("path");
          if (path == null || sess == null || resolver == null)
          {

        response.sendRedirect("/ifs/jsp-bin/ifsdevkit/sampleapps/insurance/login.jsp");
          }
          else
          {
            ibean.init(sess, resolver, path);
        %>
        <TABLE>
        <TR>
        <TH ALIGN="left">Name:</TH><TD ALIGN="left"><%= ibean.getName() %></TD>
        </TR>
        <TR>
        <TH ALIGN="left">ClaimType: </TH><TD ALIGN="left"> <%= ibean.getClaimType() %>
        </TD>
        </TR>
        <TR>
        <TH ALIGN="left">ClaimNumber: </TH><TD ALIGN="left"> <%= ibean.getClaimNumber()
        %> </TD>
        </TR>
        </TABLE>

        </BODY>
        </HTML>

        <%
          }
        %>

  ### Sample Code: InsuranceBean.java

  This sample code, `InsuranceBean.java`, creates the JavaBean that is called by `InsuranceForm.jsp`, the corresponding JSP. This JavaBean retrieves three attributes of the insurance form: Name, ClaimNumber, and ClaimType.

      /*---InsuranceBean.java---*/
      package ifsdevkit.sampleapps.insurance;

      import oracle.ifs.beans.ClassObject;
      import oracle.ifs.beans.DirectoryUser;
      import oracle.ifs.beans.FolderPathResolver;
      import oracle.ifs.beans.LibrarySession;
      import oracle.ifs.beans.PublicObject;
      import oracle.ifs.common.AttributeValue;
      import oracle.ifs.common.IfsException;

      public class InsuranceBean
      {
        /**
         * The name for the claim.
         */
        protected String m_name;

        /**
         * The type of the claim.
         */
        protected String m_claimType;

        /**
         * The claim number.
         */
        protected Long   m_claimNumber;

        /**
         * Constructor
         */
        public InsuranceBean()
        {
        }

        /**
         * Initialize the bean and populate the necessary fields.
         *
         * @param session   The <code>LibrarySession</code> object.
         *
         * @param resolver  The <code>FolderPathResolver</code> object.
         *
         * @param path  The path to the insurance object.
         *
         * @exception IfsException Thrown if operation failed.
         */
        public void init(LibrarySession session, FolderPathResolver resolver, String
      path)
        throws IfsException
        {
          try
          {
            PublicObject insuranceObj = resolver.findPublicObjectByPath(path);
            ClassObject co = insuranceObj.getClassObject();

            m_name = insuranceObj.getName();
            AttributeValue av = insuranceObj.getAttribute("CLAIMTYPE");
            if (!av.isNullValue())
            {
              m_claimType = av.getString(session);
            }
            av = insuranceObj.getAttribute("CLAIMNUMBER");
            if (!av.isNullValue())
            {
              m_claimNumber = new Long(av.getLong(session));
            }
          }
          catch (IfsException e)
          {
            e.printStackTrace();
            throw e;
          }
        }

        /**
         * Return name for the claim.
         *
         * @return The claim name.
         */
        public String getName()
        {
          return m_name;
        }

        /**
         * Return the claim type.
         *
         * @return The claim type in a <code>String</code>.
         */
        public String getClaimType()
        {
          return m_claimType;
        }

        /**
         * Return the claim number.
         *
         * @return The claim number as a <code>Long</code>.
         */
        public Long getClaimNumber()
        {
          return m_claimNumber;
        }
      }

| Copyright © 2000 Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index