Oracle Application Server Containers for J2EE 10g (9.0.4) -- Frequently Asked Questions

FAQ  Oracle Application Server Logo
JavaServer Pages
November 2003

This FAQ addresses frequently asked questions relating to JavaServer Pages(JSP) aspects of Oracle Application Server Containers for J2EE 10g (9.0.4) and is broken into the following sections:


Common Questions - JavaServer Pages Technology

1. What is "JavaServer Pages" technology?

JavaServer Pages(TM), a part of the J2EE platform, is a technology specified by Sun Microsystems as a convenient way of generating dynamic content in pages that are output by a Web application. This technology, which is closely coupled with Java servlet technology, allows you to include Java code snippets and calls to external Java components within the HTML code (or other markup code, such as XML) of your Web pages. JavaServer Pages (JSP) technology works nicely as a front-end for business logic and dynamic functionality encapsulated in JavaBeans and Enterprise JavaBeans (EJBs). 

A JSP page is translated into a Java servlet before being executed, and it processes HTTP requests and generates responses similarly to any other servlet. JSP technology offers a more convenient way to code the servlet. Translation usually occurs "on demand"--that is, as the application is run. The JSP translator is triggered by the .jsp file name extension in a URL. (the .sqljsp extension, used for SQLJ JSP pages, will also trigger the JSP translator.) 

An overview of JSP syntax elements is provided in  Chapter 1 of the OC4J JavaServer Pages Developer's guide

2. What does JSP page source look like?

Here is a simple example: 

<HTML>
<HEAD><TITLE>The Welcome User JSP</TITLE></HEAD>
<BODY>
<% String user=request.getParameter("user"); %>
<H3>Welcome <%= (user==null) ? "" : user %>!</H3>
<P><B> Today is <%= new java.util.Date() %>. Have a nice day! :-)</B></P>
<B>Enter name:</B>
<FORM METHOD=get>
<INPUT TYPE="text" NAME="user" SIZE=15>
<INPUT TYPE="submit" VALUE="Submit name">
</FORM>
</BODY>
</HTML>

This JSP page will produce something like the following output if the user inputs the name "Amy": 

Welcome Amy!

Today is Wed Jun 21 13:42:23 PDT 2000. Have a nice day! :-)
 

3. What are some of the advantages of JavaServer Pages technology?

For most situations, there are at least two general advantages in using JSP pages instead of servlets: 
  • Coding convenience--JSP syntax allows you a shortcut for coding dynamic Web pages, typically requiring much less code than equivalent servlet code. The JSP translator also automatically handles some servlet coding overhead for you, such as implementing standard JSP/servlet interfaces and creating HTTP sessions. A comparison of equivalent JSP code and servlet code is provided in the OC4J JavaServer Pages Developer's guide. In  Chapter 1, see "Convenience of JSP Coding versus Servlet Coding". 
  • Separation of static content and dynamic content--JSP technology allows separating the development efforts between the HTML code that determines static page presentation, and the Java code that processes business logic and presents dynamic content. It therefore becomes much easier to split maintenance responsibilities between presentation and layout specialists who may be proficient in HTML but not Java, and code specialists who may be proficient in Java but not HTML. In a typical JSP page, most Java code and business logic will not be within snippets embedded in the JSP page--instead, it will be in JavaBeans or Enterprise JavaBeans that are invoked from the JSP page. 

4, What are some other resources for general information and typical questions about JavaServer Pages technology?

Sun Microsystems Web sites: 

http://java.sun.com/products/jsp/ (general information and specifications) 
http://java.sun.com/products/jsp/docs.html (JSP beginner's guide) 

Other general information and "frequently asked questions" sites: 

http://www.jspinsider.com/index.view
http://www.jspin.com/ (JSP general index) 
http://www.javasoft.com/products/jsp/faq.html (FAQ list) 
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP (FAQ list) 

Oracle Technology Network sites (you will need an OTN account): 

http://forums.oracle.com/forums/index.jspa?cat=1 (public discussion) 
http://otn.oracle.com/tech/java/oc4j/content.html (OC4J download, samples, collateral) 
http://technet.oracle.com/tech/java/servlets/ (Older versions of OracleJSP download) 

Documentation on OTN: 

http://otn.oracle.com/tech/java/oc4j/pdf/oc4j_jsp_ref_r2.pdf (OC4J JavaServer Pages Reference
http://otn.oracle.com/tech/java/oc4j/pdf/oc4j_jsp_taglib_r2.pdf ( OC4J JSP Tag Libraries and Utilities Reference)

5. Are JavaServer Pages interoperable with servlets?

Yes, JSP pages are fully interoperable with servlets. JSP pages can include output from a servlet or forward to a servlet, and servlets can include output from a JSP page or forward to a JSP page. Following are some examples: 
<jsp:include page="/technology/servlet/MyServlet" flush="true" />
<jsp:forward page="/technology/servlet/MyServlet" />

For a moredetailed description refer Chapter 4, section "JSP-Servlet Interaction" in OC4J JavaServer Pages Developer's guide.

6. How do I call a JavaBean (or other Java class) from a JSP page?

Use the standard JSP useBean tag to execute a JavaBean or other Java class from a JSP page. For example: 

<jsp:useBean id="pageBean" class="mybeans.NameBean" scope="page" />

This example creates an instance, pageBean, of the mybeans.NameBean class (through a no-argument constructor). The pageBean instance can be used throughout the current JSP page--that is its "scope". (Other possible scopes are request, session, and application.) 

Later in the page, you can use pageBean as in the following example: 

Hello <%= pageBean.getNewName() %> !

The jsp:useBean tag is one of many standard JSP "action" tags using either of the following general forms: 

<jsp:tagname ... />

or: 

<jsp:tagname ... >
   ...
   ...
</jsp:tagname>

7. How do I call an Enterprise JavaBean (EJB) from a JSP page?

The key steps required for a JSP page to invoke an EJB are the following: 

1) Import the EJB package for the bean home and remote interfaces into each JSP page that makes EJB calls. (In a JSP page, use a page directive for this.) 
2) Use JNDI to look up the EJB home interface. 
3) Create the EJB remote object from the home. 
4) Invoke business methods on the remote object. 

The above steps are performed by scriplet code.  A more convenient and better approach is to use the OC4J EJB tag library. 
For more information refer to Chapter 4, section "EJB calls from JSP pages" in 
OC4J JavaServer Pages Developer's guide.
 

8. Is there JavaServer Pages functionality for including another page or forwarding to another page?

Yes, there are several options for this. 

1) You can use the include directive, known as a "static include", as follows: 

<%@ include file="/technology/jsp/userinfopage.jsp" %>

This effectively copies the page source of userinfopage.jsp into the calling JSP page at translation time, and therefore increases the size of the calling page. (This is similar in nature to a #include in the C language.) 

2) You can use the jsp:include action, known as a "dynamic include", as follows: 

<jsp:include page="/technology/jsp/userinfopage.jsp" flush="true" />

This includes output from userinfopage.jsp within the output of the calling page, taking effect during runtime instead of during translation, and is handled through the request dispatcher. It does not increase the size of the calling page, other than to add a call to the request dispatcher. (NOTE: flush="true" is always required in JSP 1.0 and JSP 1.1 environments, but not in JSP 1.2 environment) 

3) You can use the jsp:forward action, as follows: 

<jsp:forward page="/technology/jsp/userinfopage.jsp" />

Instead of simply including the content of userinfopage.jsp within the content of the calling page, this command actually stops the processing of the calling page and transfers execution to userinfopage.jsp. Anything in the output buffer from the calling page that has not already been displayed (flushed) in the browser will be cleared without being displayed. 

NOTE: A jsp:forward also forwards the original HTTP request object to the target page. This differs from HTTP response object sendRedirect(String URL) functionality, which triggers the browser to go to a specified URL without forwarding the original request object. 

For more information about these commands, see "Directives" and "JSP Actions and the <jsp: > Tag Set" in Chapter 1 of the OC4J JavaServer Pages Developer's guide.

For details of the functional differences between static includes and dynamic includes, see "Static Includes Versus Dynamic Includes" in Chapter 6 of the OC4J JavaServer Pages Developer's guide.

9. Can I forward to or include a servlet or HTML page instead of a JSP page?

Yes, in any JSP environment running in a servlet 2.1 or higher environment, you can specify a servlet class or an HTML page as well as a JSP page in any page forward (jsp:forward) or dynamic include (jsp:include) statement, as in the following examples: 

<jsp:include page="/technology/servlets/MyServlet" flush="true" />

<jsp:forward page="/technology/html/myfile.htm" />

For more information about interaction between JSP pages and servlets, see "JSP-Servlet Interaction" in Chapter 4 of the OC4J JavaServer Pages Reference.
 

10. How can I pass HTTP request parameters between pages when forwarding to or including another page?

You can use the jsp:param tag in conjunction with jsp:include or jsp:forward, as in the following example: 

<jsp:include page="/technology/templates/userinfopage.jsp" flush="true" >
   <jsp:param name="username" value="Smith" />
   <jsp:param name="userempno" value="9876" />
</jsp:include>

Alternatively, you can use URL rewriting in the jsp:include or jsp:forward, as in the following example: 

<jsp:include page="/technology/templates/userinfopage.jsp?username=Smith&userempno=9876" flush="true" />

11. Should JSP pages be used to process or display binary data?

No--JSP technology is designed for output and display of text, not binary data. For one thing, there are no methods for writing raw data into the JSP output writer (a javax.servlet.jsp.JspWriter instance). For another, during execution the JSP container preserves source code white space, including such things as tabs, carriage returns, or linefeeds. Such white space in binary data may cause errors or problems in  the data. 

To handle binary data such as graphics or data BLOBs, we recommend that you use servlets instead. 

12. What are JSP "implicit objects"?

JSP technology makes available to any JSP page a set of implicit objects. These are Java class instances that are created automatically by the JSP mechanism and that allow interaction with the underlying servlet environment. 

Available implicit objects include the following: 

  • page--this represents the JSP page and is an instance of the page implementation class that was generated by the JSP translator. 
  • request--this represents an HTTP request and is an instance of javax.servlet.http.HttpServletRequest
  • response--this represents an HTTP response and is an instance of javax.servlet.http.HttpServletResponse
  • session--this represents an HTTP session and is an instance of javax.servlet.http.HttpSession
  • application--this represents the servlet context for the Web application and is an instance of javax.servlet.ServletContext
  • out--this is an object that is used to write output to the browser from the JSP page and is an instance of javax.servlet.jsp.JspWriter
For example, you could use the following code to get the user name from the HTTP request object: 

<% String user=request.getParameter("user"); %>

For more information, see "Implicit Objects" in Chapter 1 of the OC4J JavaServer Pages Developer's guide.

13. What are "custom tag libraries" and how does the OC4J JSP container support them?

Standard JavaServer Pages technology, beginning with the JSP 1.1 specification, allows developers and vendors to create custom JSP tag libraries. A tag library defines a collection of custom actions. The tags can be used directly by developers in manually coding a JSP page, or automatically by Java development tools. Any standard tag library is portable between different JSP 1.1 or higher container implementations. 

The OC4J JSP container supports the standard framework for tag libraries, allowing customers to create their own libraries. 

OC4J JSP also provides many custom tag libraries of its own, including: 

  • JSP Markup Language (JML) tag library for for variable declarations, control flow, conditional branches, iterative loops, parameter settings, and calls to objects 
  • SQL tag library for SQL operations (includes support for connection pooling.) 
  • Caching tag libraries 
    • JESI Tag library for Edge Side Includes caching 
    • Web Object Cache tag library and API for caching within the JVM (intended for partial or interim results) 
  • Personalization tag library 
  • File-Access tag library for uploading/downloading files into/from database or a file system. 
  • SendMail Tag 
  • XML tags for transformation and parsing input stream into XML DOM objects 
  • EJB tags 
  • Web Services tag library
  • Miscellaneous utility tags 
In addition to the above tags, Oracle AS Release (9,0,4)  includes many JSP tag libraries from other components such as: 
Business Components for Java (BC4J) Tag Library, User Interface Extension (UIX) Tag Library,  Reports Tag Library, Wireless Location (Spatial) Tag Library, Ultra Search Tag Library, Portal Tag Library, Multi-media Tag Library.

For a detailed treatment of the JSP tag libraries refer to OC4J JSP Tag Libraries and Utilities Reference.

14. How can I use JavaServer Pages for database access?

In a typical scenario for a database application, a JSP page will call a JavaBean or Enterprise JavaBean and the bean will directly or indirectly access the database, generally through JDBC or perhaps SQLJ. (OC4J JSP container supports JDBC.) 

Additionally, the OC4J JSP container includes the following features to make database access more convenient: 

  • Oracle database-access JavaBeans 
  • Tag library for SQL 
NOTE: The Oracle JDBC connection cache implementation can be used with the database-access beans.  Also, the dbopen SQL tag includes an attribute datasource to support connection pooling. 

These features are described in Chapter 4 of the OC4J JSP Tag Libraries and Utilities Reference.


OC4J JSP Container - Frequently Asked Questions

15. What are the key "value-added" features of the OC4J JSP Container?

The OC4J (9.0.4) JSP container is JSP 1.2 standards compliant and  also provides extended functionality in a number of areas. 

The following extensions are provided through standards-based tag libraries and JavaBeans, and are therefore portable to non-Oracle JSP environments: 

  • extended datatypes implemented as JavaBeans that can have a specified scope (page, request, session, or application
  • integration with XML and XSL 
  • database-access JavaBeans 
  • the JSP Markup Language (JML) custom tag library, providing simplified syntax for high-level programming functionality (reducing the level of Java proficiency required).  JML tag library will be subsumed by JSP standard tag library (JSTL) in the coming release. 
  • an event handler (JspScopeListener) for events of any particular JSP scope (page, request, session, or application
  • many custom tag libraries
The following extensions are Oracle-specific: 
  • support for TLD caching
  • extended Globalization support 
  • command-line translator (used for pre-translation--for example, for deployment of executable files only) 
These features are summarized in Chapter 2 of the OC4J JavaServer Pages Developer's guide.

16. What JSP debugging features does Oracle provide?

If you are  pre-translating the pages, you can use the ojspc utility's debug option to generate a line map to the original .jsp file for debugging. 

The default is true and it prints a stack trace whenever a runtime exception occurs. Set it to false to disable this feature.

For more information about ojspc, see "The ojspc Pre-Translation Tool" in Chapter 7 of the OC4J JavaServer Pages Developer's guide.

In development environment, you can use the emit_debuginfo option to instruct the JSP translator to generate a line map to the original .jsp file for debugging.(Otherwise, line-mapping will be with respect to the page implementation class generated by the translator.) For information about how to set debugging options, see "JSP Configuration Parameters" in Chapter 3 of the OC4J JavaServer Pages Reference.

If you are using Oracle JDeveloper release 3.1 or higher, you can set breakpoints within JSP page source and can follow calls from JSP pages into JavaBeans. See the JDeveloper online help for more information. 
 

17. What are the differences between the JSP container in 9iAS 1.0.2.2 and 9.0.x ?

In Oracle9iAS Release 1.0.2.2, the first release to include OC4J, there were two JSP containers: 1) a container developed by Oracle and formerly known as OracleJSP; 2) a container licensed from Ironflare AB and formerly known as the "Orion JSP container". 

The OracleJSP container offered several advantages, including useful value-added features and enhancements such as for globalization. The Orion container also offered advantages, including superior speed, but had disadvantages as well. It did not always exhibit standard behavior when compared to the JSP 1.1 reference implementation (Tomcat), and its support for internationalization and globalization was not as complete. 

Oracle9iAS Release 2 and later integrates the OracleJSP and Orion containers into a single JSP container known as the "OC4J JSP container". This container offers the best features of both previous versions, runs efficiently as a servlet in the OC4J servlet container, and is integrated with other OC4J containers as well. The integrated container primarily consists of the OracleJSP translator and the Orion container runtime, running with a newly simplified dispatcher and the OC4J 1.0.2.2 core runtime classes. The result is one of the fastest JSP engines on the market. 

18. What is the default JSP container behavior for automatic page retranslation and class reloading?

By default, the JSP container uses the following rules for page retranslation and class reloading as a Web application is running: 
  • It will automatically retranslate a JSP page and reload the translated class whenever the page source is modified. 
  • It will automatically reload the translated class of a JSP page whenever the page is retranslated, a class called by the page is modified (presuming the class was loaded by the OC4J JSP container class loader, not the system class loader), or any page in the same application is reloaded. 
NOTE: Classes are loaded by the JSP class loader (as opposed to the system class loader) if they are in JAR files in the WEB-INF/lib directory, in class files in the WEB-INF/classes directory, or in the _pages translator output directory. 

19. How can I instruct the OC4J JSP container to not check for automatic recompilation of JSP pages and reloading of Java classes?

Set the JSP main_mode flag to justrun to avoid checking the timestamp for any possible retranslation and reloading. This is useful in speeding execution and is advisable in a deployment environment where code is not likely to change and where performance is a significant issue. 

Other main_mode settings include: 

  • reload--The dispatcher will check if any classes have been modified since loading, including translated JSP pages, JavaBeans invoked from pages, and any other dependency classes. 
  • recompile (default)--The dispatcher will check the timestamp of the JSP page, retranslate it and reload it if has been modified since loading, and execute all reload functionality as well. 


20. How to add a JSP file in the welcome-file-list if the JSP is in a sub-directory when using OC4J?

Assume the name of your file is xx.jsp inside your web/jsp/one sub-directory. 

Assuming you are deploying your Web application using the standard J2EE WAR format, you may add the file to the welcome file list in the Web deployment descriptor (web.xml): 

 <welcome-file-list> 
    ... 
    <welcome-file>web/jsp/one/xx.jsp</welcome-file> 
    ... 
 </welcome-file-list> 

 The directory web/jsp/one is relative to your web module home. 

21. How do I configure OC4J to not to remove the generated servlet code for JSPs during execution?

You can set development="true" in the <orion-web-app> element in your orion-web.xml file and that will save your generated code in the persistence directory. 
 

22. How can I use other java complers to compile my JSPs ?

You can use other compilers to compile your JSPs by adding javaccmd init parameter in global-web-application.xml
<init-param> 
        <param-name>javaccmd</param-name> 
        <param-value>/your-compiler-home/javac</param-value> 
</init-param> 

Note: Only the suported JDKs have been tested and certified.

23. How do I set the content type (for Globalization) in a JSP page?

The globalization content type of a JSP page can be set either statically (during translation) or dynamically (at runtime). 

You can set the content type statically using a JSP page directive. A page directive passes instructions to the JSP engine for use during translation and runtime. In addition to content type, this might include such things as the language of the page, classes to import, buffer size, and many other types of instructions. See Chapter ( of the OC4J JavaServer Pages Developer's guide for more information. 

Here is an example: 

<%@ page ... contentType="text/html" %>

Or the following to also specify the character set: 

<%@ page ... contentType="text/html; charset=UTF-8" %>

Either of the preceding would have effect during translation as well as runtime. 

You can set the content type dynamically by calling (in a JSP scriptlet) the setContentType() method of the HTTP response object, as in the following example: 

<%
  response.setContentType("text/html");
%>

Or the following to also specify the character set: 

<%
  String s = "EUCJIS";  // or any other dynamic value
  response.setContentType("text/html; charset=" + s);
%>

Either of the preceding would have effect during runtime only. In these cases, the JSP page itself cannot contain globalization characters other than those in the JVM's default encoding, because they could not be interpreted during translation. Also note that here you can use runtime expressions in setting the values; you cannot use runtime expressions in a page directive because the directive also has effect during translation, and runtime expressions cannot be calculated during translation. 

NOTE: A setContentType() call should be as close as possible to the top of the JSP page, preceding any buffer flushing. 

For more information about content type and other globalization considerations, see Chapter 9 in the OC4J JavaServer Pages Developer's guide

24. Does the OC4J JSP container support XSL transformation of dynamically generated XML in a JSP page?

Yes, the OC4J JSP container supports this functionality through the JML transform tag (or the equivalent JML styleSheet tag). 

Here is an example: 

<?xml version="1.0"?>
<%@ page session = "false" %>
<%@ taglib uri="/technology/WEB-INF/jmltaglib.tld" prefix="jml" %>
<jml:transform href="style/hello.xsl" >
<page>
 <title>Hello</title>
 <content>
  <paragraph>This is my first XML/XSL file!</paragraph>
 </content>
</page>
</jml:transform>

(The jmltaglib.tld file is a tag library description file, containing information that allows the JSP translator to call the appropriate Java class to handle the transform tag and trigger the appropriate processing.) 

See "XML and XSL tag Support" in Chapter 5 of the OC4J JSP Tag Libraries and Utilities Reference.
 


JSP Troubleshooting

25. How can I verify programmatically the OC4J release you are using?

To verify the OC4J JSP container release being used in a particular environment, retrieve the release number from the implicit application object in a JSP page, as follows: 

<%= application.getAttribute("oracle.jsp.versionNumber") %>

Other places you can verify the version number is in the readme.txt file or in the display output when starting OC4J. 
The version number is often necessary for bug reporting or support purposes. 

26. How can I enable logging for a JSP application?

You can enable logging for a JSP by using application.log() (the log() method of the JSP implicit application object). This starts logging to the servlet engine log file.  Also see Oracle diagnostic logging in OC4J User's Guide.

27. How can I verify that a problem is really in the JSP container, as opposed to some other component?

Write equivalent code in a servlet. If the problem still occurs in a servlet, then the root cause is in the servlet container or underlying layers, not in the JSP container.  

28. What causes the exception javax.servlet.ServletException "Unable to reload page" (for example, "Unable to reload page: /jvv/jsppages/abc.jsp because not at top level") and how can it be remedied?

There are restrictions on recompiling and reloading a dynamically included page. To work around this, you must first directly access the page to be included (i.e., open it directly from the browser). For example, if def.jsp uses jsp:include to include abc.jsp, you can work around the problem by first accessing abc.jsp directly from the browser. 

29. The generated Java method code is exceeding 65535 bytes. Is there a work around?

What you are encountering is the Java virtual machine specification limitation.  In general, it is a better idea to make smaller JSPs.  If your JSP is using tag libraries, you can also try the configuration parameter reduce_tag_code in 9.0.x. This will generate less code for the tag library invocations, but it does have a performance impact.

30. The error reported is "Attribute defined twice" when my JSP page has duplicate page directive when using OC4J (9.0.x)  How do I get around it?

J2EE 1.3 compliance test suite does not allow duplication of page directive.  To be compliant, the default behavior of the JSP container does not allow duplication of page directives.   However, to maintain backward compatibility, we have added a config option forgive_dup_dir_attr which can be set to true in global-web-application.xml to disable  the duplicate directive attribute checking.

31. When using JDK 1.4 with OC4J 9.0.2/9.0.3 I get the error "Error: Invalid class file format in D:\ProgramFiles\Java\j2re1.4.1_01\lib\rt.jar(java/lang/Object.class).  The major.minor version '48.0' is too recent for this tool to understand" . How do I work around this? 

The reason you are getting this error is that in OC4J 9.0.2/9.0.3, the tools.jar location is hardcoded in classpath in MANIFEST.MF (pointing to [OC4J_HOME]/jdk/lib/tools.jar).  When OC4J is started with a JVM from JDK 1.4, it tries to use the javac from JDK 1.3 tools.jar.  As JDK 1.3 javac  cannot understand the JDK 1.4 library ( example -  java.lang.Object), the above error message is seen. 
To workaround this problem :
- Rename [OC4J_HOME]/jdk directory to  [OC4J_HOME]/jdk1.3
- Install JDK 1.4 into [OC4J_HOME]/jdk
  Note: remember to name the directory jdk under [OC4J_HOME]

Also, the file jdk/jre/lib/security/java.security needs to be edited to include the following: 
 
# Oracle specific definitions 
auth.policy.provider=oracle.security.jazn.spi.PolicyProvider 
login.configuration.provider=oracle.security.jazn.spi.LoginConfigProvider

.


OC4J JSP Documentation

Oracle Application Server Production Documentation library
http://otn.oracle.com/documentation/appserver10g.html


Top of Page

Oracle Corporation
World Headquarters
500 Oracle Parkway
Redwood Shores, CA 94065
U.S.A.

Worldwide Inquiries:
+1.650.506.7000
Fax +1.650.506.7200
http://www.oracle.com/

Copyright © Oracle Corporation 2003
All Rights Reserved

This document is provided for informational 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 of Oracle Corporation.

All other company and product names mentioned are used
for identification purposes only and may be trademarks of
their respective owners.
 

 
E-mail this page
Printer View Printer View