OTN's Servlet-based Surveys

Part 1 - Installing the Survey Application

Revised: September 2001
First publication: August 1999
Oracle8i

The Survey Application is a servlet-based tool for defining survey questions, combining questions to create surveys, responding to surveys, and storing survey data in a database. It provides two components:

  • The Survey Definition servlet provides wizards for defining and maintaining surveys, so you never have to write a line of HTML code.
  • The Survey Response servlet reads surveys from the database, generates HTML forms, and saves user responses.

You can deploy the Survey Application to any Web server that supports Java servlets. You can also study (and modify) the source code and test it using Oracle JDeveloper. This document describes how to install and run the Survey Application. It presents the following topics:

 Required Software

  • Oracle9iAS Containers for J2EE (OC4J) downloadable from OTN
  • JDK Version 1.2 or higher.
  • Oracle Database Server 8.1.7 or higher. 
  • Oracle9i JDeveloper Beta downloadable from OTN
    (Note: Required only when Oracle9i JDeveloper is used for deploying servlets)
  •  

    Install the above required software and continue with the following  instructions on the system where  Oracle9iAS with OC4J is installed. 

Prerequisite Setup

OC4J (Oracle Container for J2EE) Setup Refer to the OC4J documentation for basic installation, testing the default configurations, starting and stopping OC4J server. Also refer the section for Servlets  in particular. This should basically give general instructions to deploy and run the web applications.
CLASSPATH - Add jndi.jar present under <OC4J_HOME>

- JDBC 2.0 related jar file : classes12.jar present under <OC4J_HOME>\lib These jars are basically for compiling JDBC related classes in .java files.

- Add Servlet.jar for running servlets from <oracle_home>\libs.Also add  <base>\SURVEYAPP\classes, where base is the directory where the survey.jar is extracted. 

JAVA_HOME Set the JAVA_HOME system variable where JDK is installed (Example: d:\jdk1.2.1 ) 

Note: <OC4J_HOME> is where your OC4J is installed. For example: d:\iSuites\j2ee\home

Installing Database Objects

Do the following steps to create a database user named survey and create all tables and sequences required by the Survey Application.

  1. Set the current working directory to SURVEYAPP.
  2. Use SQL*Plus to connect to the database as system/manager.
  3. In SQL*Plus, execute survey.sql using the following command:
    @survey

Files in the Sample

The sample is provided as a jar file Survey.jar contains the following files required for the sample : 

 
Directory or Filename Description
src.jar
Jar file containing the servlet source files.
\classes\SDServlet
Directory containing Survey Definition servlet classes.
\classes\SRServlet
Directory containing Survey Response servlet classes.
src.jar->SDServlet\web.xml
This file is used to define the Web application deployment parameters and is included in the WAR file. Only required for WAR deployment.
src.jar->SRServlet\web.xml
This file is used to define the Web application deployment parameters and is included in the WAR file. Only required for WAR deployment.
Readme.html
This file.
survey.sql
SQL script for creating Survey Application database objects.
\images
Directory containing graphics files used by the application.

Installing and Preparing the Sample

Note :<OC4J_HOME>  is where your OC4J is installed. For example: d:\iSuites\j2ee\home

Simple Deployment

 
Step 1. Extract the Survey.jar file using following command: 
jar -xvf Survey.jar 

After extracting the .jar file, it creates 'SurveyApp' directory and all required files in it. 

Step 2 . Under the SurveyApp Directory, unjar the file src.jar using the following command:
jar -xvf src.jar
Step 3. Move to SDServlet directory by using the following command:
cd SDServlet 
Step 4. Under the SDServlet directory, compile the *.java file to create the class files by using the command below: 
 javac *.java
This will create the .class files for the SDServlet module files.
Step 5. Create a folder 'SDServlet' in <OC4J_HOME>\default-web-app\Web-inf\classes directory. 
Step 6. Move the all .class files from <Base>\SurveyApp\SDServlet
to <OC4J_HOME>\default-web-app\Web-inf\classes\SDServlet directory.

<Base> is the directory where you have extracted the survery.jar file. 

Step 7.  Repeat steps 3 to 6 for SRServlet, the only change would be that the folder name should be changed to SRServlet.
Step 8. Copy the image folder from <Base>\ SurveyApp to
 <OC4J_HOME>\default-web-app\ , this will create an image folder in  the default-web-app directory.
Step 9. Register Database Connection parameters: 
To include your application specific connection parameters of your database, edit the file:
data-sources.xml under <OC4J_HOME>\config directory. Add the following lines to create a data source. Change the hostname, port, username/password, database name, driver type to suit your application. Make changes for those which are in RED below. Save the file. This will register the data-source which can be used across your application. 

 <data-source 
           class="oracle.jdbc.pool.OracleConnectionPoolDataSource" 
           name="ifso817DS" 
           location="jdbc/Loneifso817DS" 
           xa-location="jdbc/xa/ifso817XADS" 
           ejb-location="jdbc/Pooledifso817DS"
           url="jdbc:oracle:thin:@insn104a.idc.oracle.com:1521:ifso817"
           connection-driver="oracle.jdbc.driver.OracleDriver" 
           username="Survey" 
           password="Survey" 
           inactivity-timeout="30" 
  /> 

Step 10. Restart OC4J after you modify the data-sources.xml file. 
Now the sample is ready to be run

Deploying to Oracle9iAS Using J2EE  

Step 1. Extract the Survey.jar file using following command: 
jar -xvf Survey.jar 
After extracting the .jar file, it creates 'SurveyApp' directory and the all required files of the sample in it. 
Step 2. Extract src.jar present under 'SurveyApp' directory using
jar -xvf src.jar 

After extracting src.jar, SDServlet and SRServlet directories get created with the required source files in it.

Step 3. Move to SDServlet directory
cd SDServlet\ 
Step 4. Under the same directory, compile the *.java files to create the class files by using the command below: 
 javac *.java
This will create the class files for the SDServlet module.
Step 5. Create the following directories say, in d:\. 
d:\SDServlet
d:\SDServlet\src 
d:\SDServlet\WEB-INF 
d:\SdServlet\WEB-INF\classes\SDServlet
Step 6. Move 'image' directory available in 'SurveyApp' directory to <OC4J_Home>\Default-Web-App\  directory.
Step 7. Move web.xml file from <Base>SurveyApp\SDServlet to say d:\SDServlet\WEB-INF. 
Step 8. Move all the .java from <Base>SurveyApp\SDServlet to say d:\SDServlet\src
Step 9. Move the all the classfiles from SurveyApp\SDServlet  to say d:\SDServlet\WEB-INF\classes\SDServlet
Step 10. Create the war file, SDServlet.war 
       cd d:\SDServlet
       jar -cvfM SDServlet.war .
Step 11. Copy the file SDServlet.war to <OC4J_HOME>\applications.
Step 12. Open the file application.xml present in <OC4J_HOME>\config directory and 
add the following after the <web-module id="defaultWebApp" path="../default-web-app" /> line: 
<web-module id="SDServlet" path="../applications/SDServlet.war" /> 
Step 13. Open the default-web-site.xml file present in <OC4J_HOME>\config directory and 
add the following after the <default-web-app application="default" name="defaultWebApp" /> line:
<web-app application="default" name="SDServlet" root="/technology/SDServlet" />
Step 14. Repeat the steps 3 to 13 for SRServlet folder also, change the name from SDServlet to SRServlet whereever mentioned.
Step 15. Register Database Connection parameters: 
To include your application specific connection parameters of your database, edit the file:
data-sources.xml under <OC4J_HOME>\config directory. Add the following lines to create a data source. Change the hostname, port, username/password, database name, driver type to suit your application. Make changes for those which are in RED below. Save the file. This will register the data-source which can be used across your application. 

 <data-source 
           class="oracle.jdbc.pool.OracleConnectionPoolDataSource" 
           name="ifso817DS" 
           location="jdbc/Loneifso817DS"
           xa-location="jdbc/xa/ifso817XADS" 
           ejb-location="jdbc/Pooledifso817DS" 
           url="jdbc:oracle:thin:@insn104a.idc.oracle.com:1521:ifso817"
           connection-driver="oracle.jdbc.driver.OracleDriver" 
           username="Survey" 
           password="Survey" 
           inactivity-timeout="30" 
  /> 

 

Step 16. Now start the Oracle9iAS Containers for J2EE by giving the command from the 
<OC4J_HOME>\  directory. 
java -jar orion.jar 
Now the sample is ready to be run

Deploying to Oracle9iAS Using Oracle9i JDeveloper

Following are the steps to deploy and run the servlet from Oracle9i JDeveloper  (automated creation and deployment of .war file).

 
Step 1. Extract the Survey.jar file using following command: 
jar -xvf Survey.jar 
After extracting the .jar file, it creates 'SurveyApp' directory and all the required files of the sample in it. 
Step 2. Extract src.jar present under 'SurveyApp' directory using
jar -xvf src.jar
Step 3. Open Oracle 9i Jdeveloper
Step 4. Click File -> New -> Projects -> Workspace. Name the workspace as Survey.jws and create it in the directory <Base>\Survey directory, where  <Base> is the directory where you have extracted the sample. The option of 'New Empty Project' is selected by default.
Step 5. This starts the project wizard when the above mentioned 'New Empty Project' is checked. Let the Project directory be 
              <Base>\Survey directory and the name of the project be SDServlet.jpr.  Right click on SDServlet.jpr and select Project Settings -> Development -> Libraries and include the  following libraries in the "Available" list. (JDeveloper Runtime, J2EE,Oracle JDBC, Oracle 9iAS, Servlet Runtime). Also Right click on SDServlet.jpr and select Project Settings - > Common - > Input paths ->Java Source Path and make sure that it points to the directory where you have extracted this sample. 
Step 6. Create an Application Server Connection. This can be done by clicking on the Connections Node. Right click on  Application Servers and select "New Connection". Provide the appropriate connection parameters of the Application Server to which you want to deploy the servlets.
Step 7. Select SDServlet.jpr and Click on "+" button.Now add all the source files from <Base>SurveyApp\SDServlet to SDServlet.jpr It is in SDServlet directory., <Base> is the directory where you have extracted the sample.
Step 8. Make the project by right clicking on the SDServlet.jpr and selecting make option from it.
Step  9. Move all the image files available with the sample to <OC4J_Home>\Default-Web-App\Images directory. 
Step 10. Select  File -> New -> Deployment Profiles -> J2EE Web Module (WAR File), save the Deployment Profile, this brings a File Dialog, where you can mention the name of the deployment profile and the directory to which you want to save the  profile. Accept the default values for the directory and mention the file name as SDServlet.deploy Click Save.  Save the WAR file and EAR file in <Base>Survey\SDServlet directory with the name SDServlet.war and SDServlet.ear. Click OK. 
Note that <Base> is the directory where you have extracted the sample.
Step 11. The file web.xml gets automatically created while creating the deployment profile. This file needs to be edited to include servlet class name and servlet mapping, 

The file should look like:
<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">

<web-app>
   <display-name>SDSessionServletDisplayName </display-name>
   <servlet>
      <servlet-name>SDSessionServletName</servlet-name>
      <servlet-class>SDServlet.SDSessionServlet</servlet-class>
   </servlet>
   <servlet-mapping>
      <servlet-name>SDSessionServletName</servlet-name>
      <url-pattern>/</url-pattern>
   </servlet-mapping>
</web-app>

Step 12. Register Database Connection parameters: 
To include your application specific connection parameters of your database, edit the file:
data-sources.xml under <OC4J_HOME>\config directory. Add the following lines to create a data source. Change the hostname, port, username/password, database name, driver type to suit your application. Make changes for those which are in RED below. Save the file. This will register the data-source which can be used across your application. 

 <data-source 
           class="oracle.jdbc.pool.OracleConnectionPoolDataSource" 
           name="ifso817DS" 
           location="jdbc/Loneifso817DS" 
           xa-location="jdbc/xa/ifso817XADS" 
           ejb-location="jdbc/Pooledifso817DS" 
           url="jdbc:oracle:thin:@insn104a.idc.oracle.com:1521:ifso817"
           connection-driver="oracle.jdbc.driver.OracleDriver" 
           username="Survey" 
           password="Survey" 
           inactivity-timeout="30" 
  /> 

Step 13. Now start the Oracle9iAS Containers for J2EE by giving the command from the <OC4J_HOME>  directory. 
java -jar orion.jar 
Step 14. Right click on SDServlet deployment profile, and choose "Deploy to". Choose the server to which you want  to deploy your servlet .Check for the successful deployment of the servlet by looking at the deployment console. 

This completes the SDServlet deployment, now the sample is ready to run. Repeat the above steps to deploy SRServlet module also.

Running the Sample on Oracle9iAS OC4J

After installing the sample, access the page by using a URL like: 

http://<ipaddress>:<Port>/<path-to-servlet>/<sample directory>/<main-servlet-file> where 

 
<ipaddress>    is the ip-address of the machine on which OC4J is setup
<Port>    is the port on which OC4J server is running. 
  (refer to file <OC4J_HOME>\config\default-web-site.xml).   Default is: 8888
<path-to-servlet>   is the default directory where all servlets classes are placed. 
  i.e  <OC4J_HOME>\default-web-app\Survey. Refer to the Step1   in the above Installing and preparing the sample for simple deployment. This will not be there for WAR deployment.
<sample directory>   is the directory where the source files for the samples are placed.
<main-servlet-file>   is the main servlet file of the sample that is called from the browser.

For example, the URLs to the sample can be like these: 

Simple Deployment:

For running SDServlet Module:
http://152.69.168.208:8888/servlet/SDServlet.SDSessionServlet

For running SRServlet Module:
To View All The Existing Surveys:
http://152.69.168.208:8888/servlet/SRServlet.SRSessionServlet?ALLSURVEYS=YES

To View a Particular Survey:
http://152.69.169.223:8888/servlet/SRServlet.SRSessionServlet?SURVEY_ID=1&USER_ID=10&RETURN_PAGE=http://technet.oracle.com

WAR Deployment (to be used when deployed in a standard J2EE way as well as using Oracle9i JDeveloper): 
For running SDServlet Module:
http://152.69.168.209:8888/SDServlet/SDServlet.SDSessionServlet

For running SRServlet Module:
To View All The Existing Surveys:
http://152.69.168.208:8888/SRServlet/SRServlet.SRSessionServlet?ALLSURVEYS=YES

To View a Particular Survey:
http://152.69.168.209:8888/SRServlet/SRServlet.SRSessionServlet?SURVEY_ID=1&USER_ID=10&RETURN_PAGE=http://technet.oracle.com


Installing the Survey Application

Using the Survey Application

Analyzing Survey Results

How it Works


Questions or comments? Post a message in OTN's Sample Code discussion forum.

Case Study: OTN's Servlet-based Surveys
Date: August 1999, revised September 2001

This document is provided for information purposes only and the information herein is subject to change without notice. Please report any errors herein to Oracle Corporation. Oracle Corporation does not provide any warranties covering and specifically disclaims any liability in connection with this document.
Oracle is a registered trademark and Enabling the Information Age is a trademark or registered trademark of Oracle Corporation. All other company and product names mentioned are used for identification purposes only and may be trademarks of their respective owners.

Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA 94065
USA

Worldwide Inquiries:
+1.650.506.7200
Copyright © Oracle Corporation 1999, 2001
All Rights Reserved


E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy