First Publication: 01-Nov-04
Last Update: 16-Jan-06
Author: Frances Zhao
This demo illustrates some of the Servlet 2.4 features supported by OC4J:
This demo requires that the following sofware components are installed and configured correctly:
With Servlet 2.4, you can now have a servlet as a welcome file, which is useful for applications that use servlets as "Front Controllers". To do that, you first define the servlet in web.xml. From the web.xml file in this How-to:
<!-- optional -->
Then you create a welcome-file element in web.xml that specifies the above servlet name. Like:
As shown in the %HOWTO_HOME%/etc/web.xml, you can also define an alternative welcome file at the same time, which will be used if the servlet can not be found in the web application.
Servlet 2.4 provides two new listener interfaces that you can use for HTTP requests: javax.servlet.ServletRequestListener and javax.servlet.ServletRequestAttributeListener. This demo application only implements the former and would print out log messages to the OC4J console whenever the configured servlet DemoServlet is activated.
For the implemented listener, each time the web application receives a new request, the listener is notified and its requestInitialized() method is called. This method's parameter is a javax.servlet.ServletRequestEvent type. Calling this object's getServletRequest() method gives the developer access to the new request, a javax.servlet.ServletRequest type (to do whatever they want with the new request). See %HOWTO_HOME%/src/web/java/ServletReqLsnr.java for details.
The implemented listener must also have a constructor with no arguments. You define your implemented listener in web.xml, like:
Servlet 2.4 adds some new methods to the ServletRequest interface:
These methods provide a mechanism to query the low-level IP connection details and understand how the connection routed. This How-to application also calls these methods as illustration, as in %HOWTO_HOME%/src/web/java/DemoServlet.java.
The following instructions are for running this demonstration on a standalone instance of Oracle Containers for J2EE 10g (10.1.3).
Please check to make sure that the following properties are configured correctly in the ant-oracle.properties file located in the root of the sample's distribution (NOTE: Some of these properties will default to the values of corresponding environment variables as noted below. If you have these variables setup in your environment you may not have to alter the values in the file). If necessary, modify these variable to the proper values for you environment:
Stand Alone Installation: %ORACLE_HOME%/bin/oc4j start
Note that the oc4j command expects the JAVA_HOME environment variable to point to a full JDK installation.
OracleAS Managed Installation: %ORACLE_HOME%/opmn/bin/opmnctl startall
In the top-level %HOWTO_HOME% directory, type the command:
You should now have newly created servlet_demo.ear and servlet_demo-web.war in your %HOWTO_HOME%/lib directory.
This command would also attempt to deploy the application if the build is successful. It will first test whether OC4J is running.
You can also deploy and bind the application separately by using the following command. Make sure the %ORACLE_HOME% environment variable is defined. In the top-level %HOWTO_HOME% directory, type the command:
In a browser window, browse to:
If the website hostname or port number are different, then use those values instead.
Alternatively, you can use this link to access the demo servlet. Reload the page several times. Check the result page, but also watch the demo listener updating the log in the OC4J console.
In this document, you should have: