Server Bea Weblogic
Server Bea Weblogic
Server Bea Weblogic
Server ™
Troubleshooting 7-i
Debugging Information in the Browser 7-i
Error 404—Not Found 7-i
Error 500—Internal Server Error 7-ii
Error 503—Service Unavailable 7-ii
Errors Using the <jsp:plugin> tag 7-ii
Symptoms in the Log File 7-ii
Page Compilation Failed Errors 7-ii
About This Document
This document describes how to program e-commerce applications by using JavaServer Pages (JSP) and WebLogic
Server.
The document is organized as follows:
n Chapter 1, “JSP Overview,”provides an introduction and reference for the basic syntax of JSP and
information about how to use JSP with WebLogic Server.
n Chapter 2, “Administering WebLogic JSP,” provides a brief overview of administration and
configuration tasks for WebLogic JSP.
n Chapter 3, “WebLogic JSP Reference,” provides a reference on writing JSPs.
n Chapter 4, “Using Custom WebLogic JSP Tags (cache, process, repeat),” discusses the use of three
custom JSP tags provided with the WebLogic Server distribution: the cache tag, the repeat tag,
and the process tag.
n Chapter 7, “Troubleshooting,” describes several techniques for debugging your JSP files.
Audience
This document is written for application developers who want to build e-commerce applications using JSP and the
Java 2 Platform, Enterprise Edition (J2EE) from Sun Microsystems. It is assumed that readers know Web
technologies, object-oriented programming techniques, and the Java programming language.
Related Information
n JSP 1.1 Specification from Sun Microsystems, available at
http://java.sun.com/products/jsp/download.html.
Contact Us!
Your feedback on BEA documentation is important to us. Send us e-mail at [email protected] if you have
questions or comments. Your comments will be reviewed directly by the BEA professionals who create and
update the documentation.
In your e-mail message, please indicate the software name and version you are using, as well as the title and
document date of your documentation. If you have any questions about this version of BEA WebLogic Server, or
if you have problems installing and running BEA WebLogic Server, contact BEA Customer Support through BEA
WebSupport at http://www.bea.com. You can also contact Customer Support by using the contact information
provided on the Customer Support Card, which is included in the product package.
When contacting Customer Support, be prepared to provide the following information:
Documentation Conventions
The following documentation conventions are used throughout this document.
Convention Usage
monospace Code samples, commands and their options, Java classes, data types,
text directories, and file names and their extensions. Monospace text also
indicates text that you enter from the keyboard.
Examples:
import java.util.Enumeration;
chmod u+w *
config/examples/applications
.java
config.xml
float
. Indicates the omission of items from a code example or from a syntax line.
.
.
CHAPTER
1 JSP Overview
This document is an introduction and reference for the basic syntax of JavaServer Pages (JSP). It provides
information about how to use JSP with WebLogic Server. It is not intended as a comprehensive guide to
programming with JSP.
The following sections provide an overview of JSP:
n What Is JSP?
n Additional Information
What Is JSP?
JavaServer Pages (JSP) is a Sun Microsystems specification for combining Java with HTML to provide dynamic
content for Web pages. When you create dynamic content, JSPs are more convenient to write than HTTP servlets
because they allow you to embed Java code directly into your HTML pages, in contrast with HTTP servlets, in which
you embed HTML inside Java code. JSP is part of the Java 2 Enterprise Edition (J2EE).
JSP enables you to separate the dynamic content of a Web page from its presentation. It caters to two different types
of developers: HTML developers, who are responsible for the graphical design of the page, and Java developers, who
handle the development of software to create the dynamic content.
Because JSP is part of the J2EE standard, you can deploy JSPs on a variety of platforms, including WebLogic Server.
In addition, third-party vendors and application developers can provide JavaBean components and define custom
JSP tags that can be referenced from a JSP page to provide dynamic content.
Additional Information
n JavaServer Pages Tutorial from Sun Microsystems at
http://java.sun.com/products/jsp/docs.html
2 Administering WebLogic
JSP
The following sections provide an overview of administration and configuration tasks required to deploy WebLogic
JavaServer Pages (JSP):
n Overview of WebLogic JSP Administration
The following sections provide reference information for writing JavaServer Pages (JSPs):
n JSP Tags
n Scriptlets
n Expressions
n Actions
Note: Use these implicit objects only within Scriptlets or Expressions. Using these keywords
from a method defined in a declaration causes a translation-time compilation error because
such usage causes your page to reference an undefined variable.
request
request represents the HttpServletRequest object. It contains information about the
request from the browser and has several useful methods for getting cookie, header, and
session data.
response
response represents the HttpServletResponse object and several useful methods for
setting the response sent back to the browser from your JSP page. Examples of these
responses include cookies and other header information.
Warning: You cannot use the response.getWriter() method from within a JSP page; if
you do, a run-time exception is thrown. Use the out keyword to send the JSP response back
to the browser from within your scriptlet code whenever possible. The WebLogic Server
implementation of javax.servlet.jsp.JspWriter uses
javax.servlet.ServletOutputStream, which implies that you can use
response.getServletOutputStream(). Keep in mind, however, that this implementation
is specific to WebLogic Server. To keep your code maintainable and portable, use the out
keyword.
out
out is an instance of javax.jsp.JspWriter that has several methods you can use to send
output back to the browser.
If you are using a method that requires an output stream, then JspWriter does not work. You
can work around this limitation by supplying a buffered stream and then writing this stream
to out. For example, the following code shows how to write an exception stack trace to out:
ByteArrayOutputStream ostr = new ByteArrayOutputStream();
exception.printStackTrace(new PrintWriter(ostr));
out.print(ostr);
pageContext
pageContext represents a javax.servlet.jsp.PageContext object. It is a convenience
API for accessing various scoped namespaces and servlet-related objects, and provides
wrapper methods for common servlet-related functionality.
session
session represents a javax.servlet.http.HttpSession object for the request. The
session directive is set to true by default, so the session is valid by default. The JSP 1.1
specification states that if the session directive is set to false, then using the session
keyword results in a fatal translation time error. For more information about using sessions
with servlets, see Programming WebLogic HTTP Servlets at
http://e-docs.bea.com/wls/docs70/servlet/index.html.
application
application represents a javax.servlet.ServletContext object. Use it to find
information about the servlet engine and the servlet environment.
When forwarding or including requests, you can access the servlet requestDispatcher
using the ServletContext, or you can use the JSP forward directive for forwarding
requests to other servlets, and the JSP include directive for including output from other
servlets.
config
config represents a javax.servlet.ServletConfig object and provides access to the
servlet instance initialization parameters.
page
page represents the servlet instance generated from this JSP page. It is synonymous with the
Java keyword this when used in your scriptlet code.
To use page, you must cast it to the class type of the servlet that implements the JSP page,
because it is defined as an instance of java.lang.Object. By default, the servlet class is
named after the JSP filename. For convenience, we recommend that you use the Java
keyword this to reference the servlet instance and get access to initialization parameters,
instead of using page.
For more information on the underlying HTTP servlet framework, see the related developers guide, Programming
WebLogic HTTP Servlets at http://e-docs.bea.com/wls/docs70/servlet/index.html.
Directives for WebLogic JSP
Use directives to instruct WebLogic JSP to perform certain functions or interpret the JSP page in a particular way.
You can insert a directive anywhere in a JSP page. The position is generally irrelevant (except for the include
directive), and you can use multiple directive tags. A directive consists of a directive type and one or more
attributes of that type.
You can use either of two types of syntax: shorthand or XML:
n Shorthand:
<%@ dir_type dir_attr %>
n XML:
<jsp:directive.dir_type dir_attr />
Replace dir_type with the directive type, and dir_attr with a list of one or more directive attributes for that
directive type.
There are three types of directives page, taglib, or include.
Scriptlets
JSP scriptlets make up the Java body of your JSP servlet’s HTTP response. To include a scriptlet in your JSP page,
use the shorthand or XML scriptlet tags shown here:
Shorthand:
<%
// Your Java code goes here
%>
XML:
<jsp:scriptlet>
// Your Java code goes here
</jsp:scriptlet>
Note the following features of scriptlets:
n You can have multiple blocks of scriptlet Java code mixed with plain HTML.
n You can switch between HTML and Java code anywhere, even within Java constructs and
blocks. In “Example of a JSP with HTML and Embedded Java” on page vii the example
declares a Java loop, switches to HTML, and then switches back to Java to close the loop. The
HTML within the loop is generated as output multiple times as the loop iterates.
n You can use the predefined variable out to print HTML text directly to the servlet output stream
from your Java code. Call the print() method to add a string to the HTTP page response.
n The Java tag is an inline tag; it does not force a new paragraph.
Expressions
To include an expression in your JSP file, use the following tag:
<%= expr %>
Replace expr with a Java expression. When the expression is evaluated, its string representation is placed
inline in the HTML response page. It is shorthand for
<% out.print( expr ); %>
This technique enables you to make your HTML more readable in the JSP page. Note the use of the expression
tag in the example in the next section.
<body bgcolor=#ffffff>
<center>
<h1> <font color=#DB1260> Hello World Test </font></h1>
<font color=navy>
<%
</font>
<p> This is not Java!
<p><i>Middle stuff on page</i>
<p>
<font color=navy>
<%
for (int i = 1; i<=3; i++) {
%>
<h2>This is HTML in a Java loop! <%= i %> </h2>
<%
}
%>
</font>
</center>
</body>
</html>
After the code shown here is compiled, the resulting page is displayed in a browser as follows:
Actions
You use JSP actions to modify, use, or create objects that are reperesented by JavaBeans. Actions use XML syntax
exclusively.
<jsp:useBean id="cart"
class="examples.jsp.ShoppingCart" scope="session"/>
If such an object does not currently exist, the JSP attempts to create a new object, and stores it in the HTTP session
under the name cart. The class should be available in the CLASSPATH used to start WebLogic Server, or in the
WEB-INF/classes directory of the Web Application containing the JSP.
It is good practice to use an errorPage directive with the <jsp:useBean> tag because there are run-time
exceptions that must be caught. If you do not use an errorPage directive, the class referenced in the JavaBean
cannot be created, an InstantiationException is thrown, and an error message is returned to the browser.
You can use the type attribute to cast the JavaBean type to another object or interface, provided that it is a legal
type cast operation within Java. If you use the attribute without the class attribute, your JavaBean object must
already exist in the scope specified. If it is not legal, an InstantiationException is thrown.
Note: If you use the type attribute without the class attribute, a JavaBean object is never
instantiated, and you should not attempt to use the tag format to include a body. Instead, use
the single tag format. In this case, the JavaBean must exist in the specified scope, or an
InstantiationException is thrown. Use an errorPage directive to catch the potential
exception.
Forwarding Requests
If you are using any type of authentication, a forwarded request made with the <jsp:forward> tag, by default,
does not require the user to be re-authenticated. You can change this behavior to require authentication of a
forwarded request by adding the <check-auth-on-forward/> element to the
<container-descriptor> element of the WebLogic-specific deployment descriptor, weblogic.xml. For
example:
<container-descriptor>
<check-auth-on-forward/>
</container-descriptor>
For information on editing the WebLogic-specific deployment descriptor, see Writing the WebLogic-Specific
Deployment Descriptor at
http://e-docs.bea.com/wls/docs70/webapp/webappdeployment.html#weblogic-xml.
Including Requests
You can use the <jsp:include> tag to include another resource in a JSP. This tag takes two attributes:
page
Use the page attribute to specify the included resource. For example:
<jsp:include page=”somePage.jsp”/>
flush
Setting this boolean attribute to true buffers the page output and then flushes the buffer
before including the resource.
Setting flush=”false” can be useful when the <jsp:include> tag is located within another tag on the JSP
page and you want the included resource to be processed by the tag.
n If session data must be of a user-defined type, the data class should be serializable. Furthermore,
the session should store the serialized representation of the data object. Serialization should be
compatible across versions of the data class.
n If you need to log out an authenticated user, see the following section in Programming
WebLogic HTTP Servlets: Logging Out and Ending a Session at
http://e-docs.bea.com/wls/docs70/servlet/progtasks.html#sessionend.
<jsp:params>
<param name="weblogic_url" value="t3://localhost:7001">
<param name="poolname" value="demoPool">
</jsp:params>
<jsp:fallback>
<font color=#FF0000>Sorry, cannot run java applet!!</font>
</jsp:fallback>
</jsp:plugin>
The sample JSP syntax shown here instructs the browser to download the Java Plug-in version 1.3.1 (if it has not
been downloaded previously), and run the applet identified by the code attribute from the location specified by
codebase.
The jreversion attribute identifies the spec version of the Java Plug-in that the applet requires to operate. The
Web browser attempts to use this version of the Java Plug-in. If the plug-in is not already installed on the browser,
the nspluginurl and iepluginurl attributes specify URLs where the Java Plug-in can be downloaded from
the Sun Web site. Once the plug-in is installed on the Web browser, it is not downloaded again.
Because WebLogic Server uses the Java 1.3.x VM, you must specify the Java Plug-in version 1.3.x in the
<jsp:plugin> tag. To specify the 1.3 JVM in the previous example code, replace the corresponding attribute
values with the following:
jreversion="1.3"
nspluginurl=
"http://java.sun.com/products/plugin/1.3/plugin-install.html"
iepluginurl=
"http://java.sun.com/products/plugin/1.3/jinstall-131-win32.cab"
The other attributes of the plug-in action correspond with those of the <APPLET> tag. You specify applet
parameters within a pair of <params> tags, nested within the <jsp:plugin> and </jsp:plugin> tags.
The <jsp:fallback> tags allow you to substitute HTML for browsers that are not supported by the
<jsp:plugin> action. The HTML nested between the <fallback> and </jsp:fallback> tags is sent
instead of the plug-in syntax.
Using the WebLogic JSP Compiler
Because the JSP Servlet automatically calls the WebLogic JSP compiler to process your JSP pages, you generally
do not need to use the compiler directly. However, in some situations, such as when you are debugging, accessing
the compiler directly is useful. This section is a reference for the compiler.
The WebLogic JSP compiler parses your JSP file into a .java file, and then compiles the generated .java file
into a Java class, using a standard Java compiler.
Note: If you are precompiling JSPs that are part of a Web Application and that reference resources
in the Web Application (such as a JSP tag library), you must use the -webapp flag to specify
the location of the Web Application. The -webapp flag is described in the following listing of
JSP compiler options.
The most common mappings are built into the JSP compiler. Use this option only if a desired
charset mapping is not recognized.
-commentary
Causes the JSP compiler to include comments from the JSP in the generated HTML page. If
this option is omitted, comments do not appear in the generated HTML page.
-compileAll
Recursively compiles all JSPs in the current directory, or in the directory specified with the
-webapp flag. (See the listing for -webapp in this list of options.). JSPs in subdirectories are
also compiled.
-compileFlags
Passes one or more command-line flags to the compiler. Enclose multiple flags in quotes,
separated by a space. For example:
java weblogic.jspc -compileFlags "-g -v" myFile.jsp
-compiler
Specifies the Java compiler to be used to compile the class file from the generated Java source
code. The default compiler used is javac. The Java compiler program should be in your PATH
unless you specify the absolute path to the compiler explicitly.
-compilerclass
Runs a Java compiler as a Java class and not as a native executable.
-d <dir>
Specifies the destination of the compiled output (that is, the class file). Use this option as a
shortcut for placing the compiled classes in a directory that is already in your CLASSPATH.
-depend
If a previously generated class file for a JSP has a more recent date stamp than the JSP source
file, the JSP is not recompiled.
-debug
Compile with debugging on.
-deprecation
Warn about the use of deprecated methods in the generated Java source file when compiling
the source file into a class file.
-docroot directory
See -webapp.
-encoding default|named character encoding
Valid arguments include (a) default which specifices using the default character encoding
of your JDK, (b) a named character encoding, such as 8859_1. If the -encoding flag is not
specified, an array of bytes is used.
-g
Instructs the Java compiler to include debugging information in the class file.
-help
Displays a list of all the available flags for the JSP compiler.
-J
Takes a list of options that are passed to your compiler.
-k
When compiling multiple JSPs with with a single command, the compiler continues
compiling even if one or more of the JSPs failed to compile.
-keepgenerated
Keeps the Java source code files that are created as an intermediary step in the compilation
process. Normally these files are deleted after compilation.
-noTryBlocks
If a JSP file has numerous or deeply nested custom JSP tags and you receive a
java.lang.VerifyError exception when compiling, use this flag to allow the JSPs to
compile correctly.
-nowarn
Turns off warning messages from the Java compiler.
-nowrite
Runs the compilation process without actually producing a .class file. If you combine this
option with the -keepgenerated flag, the compiler creates only the intermediate .java file,
which can be useful for debugging.
-O
Compiles the generated Java source file with optimization turned on. This option overrides
the -g flag.
-package packageName
Sets the package name that is prepended to the package name of the generated Java HTTP
servlet. Defaults to jsp_servlet.
-superclass classname
Sets the classname of the superclass extended by the generated servlet. The named superclass
must be a derivative of HttpServlet or GenericServlet.
-verbose
Passes the verbose flag to the Java compiler specified with the compiler flag. See the
compiler documentation for more information. The default is off.
-verboseJavac
Prints messages generated by the designated JSP compiler.
-version
Prints the version of the JSP compiler.
-webapp directory
Name of a directory containing a Web Application in exploded directory format. If your JSP
contains references to resources in a Web Application such as a JSP tag library or other Java
classes, the JSP compiler will look for those resources in this directory. If you omit this flag
when compiling a JSP that requires resources from a Web Application, the compilation will
fail.
Precompiling JSPs
You can configure WebLogic Server to precompile your JSPs when a Web Application is deployed or re-deployed
or when WebLogic Server starts up by setting the precompile parameter to true in the <jsp-descriptor>
element of the weblogic.xml deployment descriptor:
For more information on the web.xml deployment descriptor, see Assembling and Configuring Web
Applications at http://e-docs.bea.com/wls/docs70/webapp/index.html.
CHAPTER
The following sections describe the use of three custom JSP tags—cache, repeat, and process—provided
with the WebLogic Server distribution:
n Overview of WebLogic Custom JSP Tags
n Cache Tag
n Process Tag
n Repeat Tag
3. Reference the tag library in your JSP with the taglib directive. For example:
<%@ taglib uri="weblogic-tags.tld" prefix="wl" %>
Cache Tag
The cache tag enables caching the work that is done within the body of the tag. It supports both output (transform)
data and input (calculated) data. Output caching refers to the content generated by the code within the tag. Input
caching refers to the values to which variables are set by the code within the tag. Output caching is useful when
the final form of the content is the important thing to cache. Input caching is important when the view of the data
can vary independently of the data calculated within the tag.
Caches are stored using soft references to prevent the caching system from using too much system memory.
Unfortunately, due to incompatibilities with the HotSpot VM and the Classic VM, soft references are not used
when WebLogic Server is running within the HotSpot VM.
Refreshing a Cache
You can force the refresh of a cache by setting the _cache_refresh object to true in the scope that you want
affected. For example, to refresh a cache at session scope, specify the following:
<% request.setAttribute("_cache_refresh", "true"); %>
If you want all caches to be refreshed, set the cache to the application scope. If you want all the caches for a
user to be refreshed, set it in the session scope. If you want all the caches in the current request to be refreshed,
set the _cache_refresh object either as a parameter or in the request.
The <wl:cache> tag specifies content that must be updated each time it is displayed. The statements between
the <wl:cache> and </wl:cache> tags are only executed if the cache has expired or if any of the values of
the key attributes (see the Cache Tag Attributes table) have changed.
Flushing a Cache
Flushing a cache forces the cached values to be erased; the next time the cache is accessed, the values are
recalculated. To flush a cache, set its flush attribute to true. The cache must be named using the name attribute.
If the cache has the size attribute set, all values are flushed. If the cache sets the key attribute but not the size
attribute, you can flush a specific cache by specifying its key along with any other attributes required to uniquely
identify the cache (such as scope or vars).
For example:
1. Define the cache.
<wl:cache name="dbtable" key="parameter.tablename"
scope="application">
// read the table and output it to the page
</wl:cache>
scope no application Specifies the scope in which the data is cached. Valid
scopes include: page, request, session,
application. Most caches will be either session
or application scope.
async no false If the async parameter is set to true, the cache will
be updated asynchronously, if possible. The user that
initiates the cache hit sees the old data.
Table 4-1 Cache Tag Attributes
Attribute Required Default Value Description
size no -1 (unlimited) For caches that use keys, the number of entries allowed.
The default is an unlimited cache of keys. With a
limited number of keys the tag uses a least-used system
to order the cache. Changing the value of the size
attribute of a cache that has already been used does not
change the size of that cache.
flush no none When set to true, the cache is flushed. This attribute
must be set in an empty tag (ends with /).
The following examples show how you can use the <wl:cache> tag.
<wl:cache>
<!--the content between these tags will only be
refreshed on server restart-->
</wl:cache>
Process Tag
Use the <wl:process> tag for query parameter-based flow control. By using a combination of the tag’s four
attributes, you can selectively execute the statements between the <wl:process> and </wl:process> tags.
The process tag may also be used to declaratively process the results of form submissions. By specifying
conditions based on the values of request parameters you can include or not include JSP syntax on your page.
The following examples show how you can use the <wl:process> tag:
<wl:process notname="update">
<wl:process notname="delete">
<!--Only show this if there is no update or delete parameter-->
<form action="<%= request.getRequestURI() %>">
<input type="text" name="name"/>
<input type="submit" name="update" value="Update"/>
<input type="submit" name="delete" value="Delete"/>
</form>
</wl:process>
</wl:process>
<wl:process name="update">
<!-- do the update -->
</wl:process>
<wl:process name="delete">
<!--do the delete-->
</wl:process>
Repeat Tag
Use the <wl:repeat> tag to iterate over many different types of sets, including Enumerations, Iterators,
Collections, Arrays of Objects, Vectors, ResultSets, ResultSetMetaData, and the keys of a Hashtable. You can
also just loop a certain number of times by using the count attribute. Use the set attribute to specify the type of
Java objects.
The following example shows how you can use the <wl:repeat> tag.
The following sections describe how to use WebLogic JSP form validation tags:
n Overview of WebLogic JSP Form Validation Tags
n Validate the text in the field against a regular expression (Regular Expression Validator
class).
n Compare two fields in the form (Compare Validator class).
n Perform custom validation by means of a Java class that you write (Custom Validator class).
n <wl:form>
n <wl:validator>
When a validation tag determines that data in a field is not been input correctly, the page is re-displayed and the
fields that need to be re-entered are flagged with text or an image to alert the end user. Once the form is correctly
filled out, the end user’s browser displays a new page specified by the validation tag.
<wl:summary>
<wl:summary> is the parent tag for validation. Place the opening <wl:summary> tag before any other element
or HTML code in the JSP. Place the closing </wl:summary> tag anywhere after the closing </wl:form>
tag(s).
name
(Optional) Name of a vector variable that holds all validation error messages generated by the
<wl:validator> tags on the JSP page. If you do not define this attribute, the default value,
errorVector, is used. The text of the error message is defined with the errorMessage
attribute of the <wl:validator> tag.
To display the values in this vector, use the <wl:errors/> tag. To use the <wl:errors/>
tag, place the tag on the page where you want the output to appear. For example:
<wl:errors color="red"/>
Where errorVector is the name of the vector assigned using the name attribute of the
<wl:summary> tag.
Where summary is the name of the vector assigned using the name attribute of the
<wl:summary> tag.
redirectPage
URL for the page that is displayed if the form validation does not return errors. This attribute
is not required if you specify a URL in the action attribute of the <wl:form> tag.
Note: Do not set the redirectPage attribute to the same page containing the <wl:summary>
tag—you will create an infinite loop causing a StackOverFlow exception.
<wl:form>
The <wl:form> tag is similar to the HTML <form> tag and defines an HTML form that can be validated using
the the WebLogic JSP form validataion tags. You can define multiple forms on a single JSP by uniquely
identifying each form using the name attribute.
method
Enter GET or POST. Functions exactly as the method attribute of the HTML <form> tag.
action
URL for the page that is displayed if the form validation does not return errors. The value of
this attribute takes precedence over the value of the redirectPage attribute of the
<wl:summary> tag and is useful if you have multiple forms on a single JSP page.
Note: Do not set the action attribute to the same page containing the <wl:form> tag—you
will create an infinite loop causing a StackOverFlow exception.
name
Functions exactly as the name attribute of the HTML <form> tag. Identifies the form when
multiple forms are used on the same page. The name attribute is also useful for JavaScript
references to a form.
<wl:validator>
Use one or more <wl:validator> tags for each form field. If, for instance, you want to validate the input
against a regular expression and also require that something be entered into the field you would use two
<wl:validator> tags, one using the RequiredFieldValidator class and another using the
RegExpValidator class. (You need to use both of these validators because blank values are evaluated by the
Regular Expression Field Validator as valid.)
errorMessage
A string that is stored in the vector variable defined by the name attribute of the
<wl:summary> tag.
expression
When using the RegExpValidator class, the regular expression to be evaluated.
If you are not using RegExpValidator, you can omit this attribute.
fieldToValidate
Name of the form field to be validated. The name of the field is defined with the name attribute
of the HTML <input> tag.
validatorClass
The name of the Java class that executes the validation logic. Three classes are provided for
your use. You can also create your own custom validator class. For more information, see
“Using a Custom Validator Class” on page viii.
The available validation classes are:
weblogicx.jsp.tags.validators.RequiredFieldValidator
Validates that some text has been entered in the field.
weblogicx.jsp.tags.validators.RegExpValidator
Validates the text in the field using a standard regular expression.
Note: A blank value is evaluated as valid.
weblogicx.jsp.tags.validators.CompareValidator
Checks to see if two fields contain the same string. When using this class, set the
fieldToValidate attribute to the two fields you want to compare. For example:
fieldToValidate="field_1,field_2"
Note: If both fields are blank, the comparison is evaluated as valid.
myPackage.myValidatorClass
Specifies a custom validator class.
<wl:validator
errorMessage="Field_1 is required" expression=""
fieldToValidate="field_1"
validatorClass=
"weblogicx.jsp.tags.validators.RequiredFieldValidator"
>
<img src="images/warning.gif">
<font color=red>Field 1 is a required field</font>
</wl:validator>
<p> <input type="text" name = "field_1"> </p>
<p> <input type="text" name = "field_2"> </p>
<p> <input type="submit" value="Submit FirstForm"> </p>
</wl:form>
If the user fails to enter a value in field_1, the page is redisplayed, showing a
warning.gif image, followed by the text (in red) “Field 1 is a required field,”
followed by the blank field for the user to re-enter the value.
2. Copy the weblogic-vtags.jar file from the ext directory of your WebLogic Server
installation into the WEB-INF/lib directory of your Web Application. You may need to create
this directory.
3. Configure your Web Application to use the tag library by adding a <taglib> element to the
web.xml deployment descriptor for the Web Application. For example:
<taglib>
<taglib-uri>tagl</taglib-uri>
<taglib-location>
/WEB-INF/lib/weblogic-vtags.jar
</taglib-location>
</taglib>
For more information on Web Application deployment descriptors, see Writing Web Application
Deployment Descriptors at
http://e-docs.bea.com/wls/docs70/webapp/webappdeployment.html.
3. Add the following entry to the web.xml deployment descriptor of your Web Application:
<taglib>
<taglib-uri>input</taglib-uri>
<taglib-location>/WEB-INF/lib/input.jar</taglib-location>
</taglib>
Using a Custom Validator Class
To use your own validator class:
1. Write a Java class that extends the weblogicx.jsp.tags.validators.CustomizableAdapter
abstract class. For more information, see “Extending the CustomizableAdapter Class” on page viii.
2. Implement the validate() method. In this method:
a. Look up the value of the field you are validating from the ServletRequest object. For
example:
String val = req.getParameter("field_1");
import weblogicx.jsp.tags.validators.CustomizableAdapter;
public myCustomValidator(){
super();
}
if (true) {
return true;
}
return false;
}
<wl:summary
name="summary"
headerText="<font color=red>Some fields have not been filled out
correctly.</font>"
redirectPage="successPage.jsp"
>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF">
<p>
<p>
<p>
</wl:form>
</wl:summary>
</body>
</html>
CHAPTER
The following sections describe how to use the WebLogic EJB-to-JSP integration tool to create JSP tag libraries that
you can use to invoke EJBs in a JavaServer Page (JSP). This document assumes at least some familiarity with both
EJB and JSP.
n Overview of the WebLogic EJB-to-JSP Integration Tool
n Basic Operation
n Troubleshooting
n Default Attributes
Basic Operation
You can run the WebLogic EJB-to-JSP integration tool in command-line mode or graphical mode. For all but the
simplest EJBs, the graphical tool is preferable.
Invoke the graphical tool as follows:
java weblogic.servlet.ejb2jsp.gui.Main
Initially, no ejb2jsp project is loaded by the Web Application. Create a new project by selecting the File -> New
menu item, browsing in the file chooser to an EJB jar file, and selecting it. Once initialized, you can modify, save,
and reload ejb2jsp projects for future modification.
The composition of the generated tag library is simple: for each method, of each EJB, in the jar file, a JSP tag is
generated, with the same name as the method. Each tag expects as many attributes as the corresponding method
has parameters.
Troubleshooting
Sometimes, a project fails to build because of errors or conflicts. This section describes the reasons for those
errors, and how they may be resolved.
n Missing build information One of the necessary fields in the Build Options panel is
unspecified, like the java compiler, the code package name, or a directory where the output can
be saved. The missing field(s) must be filled in before the build can succeed.
n Duplicate tag names When an EJB jar is loaded, the tool records a tag for each method on the
EJB, and the tag name is the same as the method name. If the EJB has overloaded methods
(methods with the same name but different signatures), the tag names conflict. Resolve the
conflict by renaming one of the tags or by disabling one of the tags. To rename a tag, navigate
to the tag in question using the tree hierarchy in the left window of the tool. In the tag panel that
appears in the right window, modify the Tag Name field. To disable a tag, navigate to the tag in
question using the tree hierarchy in the left window of the tool. In the tag panel that appears in
the right window, deselect the Generate Tag box. For EJB jars that contain multiple EJBs, you
can disable tags for an entire bean may as well.
n Meaningless attribute names arg0, arg1... This error occurs when reasonable attribute names
for a tag could not be inferred from the EJB's interface source files. To fix this error, navigate to
the tag in question in the project hierarchy tree. Select each of the attribute tree leaves below the
tag, in order. For each attribute, assign a reasonable name to the Attribute Name field, in the
panel that appears on the right side of the tool.
n Duplicate attribute names This occurs when a single tag expecting multiple attributes has two
attributes with the same name. Navigate to the attribute(s) in question, and rename attributes so
that they are all unique for the tag.
Default Attributes
By default, the tag for each method requires that all of its attributes (method parameters) be set on each tag
instance. However, the tool will also allow "default" method parameters to be specified, in case they are not given
in the JSP tag. You can specify default attributes/parameters in the Attribute window of the EJB-to-JSP tool. The
parameter default can come from an simple EXPRESSION, or if more complex processing is required, a default
METHOD body may be written. For example, in the Trader example in “Overview of the WebLogic EJB-to-JSP
Integration Tool” on page i, suppose you want the “buy” tag to operate on stock symbol “XYZ” if none is
specified. In the Attribute panel for the “stockSymbol” attribute of the “buy” tag, you set the “Default Attribute
Value” field to EXPRESSION, and enter “XYZ” (quotes included!) in the Default Expression field. The buy tag
then acts as if the stockSymbol="XYZ" attribute were present, unless some other value is specified.
Or if you want the shares attribute of the "buy" tag to be a random number between 0-100, we would set "Default
Attribute Value" to METHOD, and in the Default Method Body area, you write the body of a Java method that
returns int (the expected type for the "shares" attribute of the "buy" method):
long seed = System.currentTimeMillis();
java.util.Random rand = new java.util.Random(seed);
int ret = rand.nextInt();
/* ensure that it is positive...*/
ret = Math.abs(ret);
/* and < 100 */
return ret % 100;
Because your default method bodies appear within a JSP tag handler, your code has access to the pageContext
variable. From the JSP PageContext, you can gain access to the current HttpServletRequest or HttpSession, and
use session data or request parameters to generate default method parameters. For example, to pull the "shares"
parameter for the "buy" method out of a ServletRequest parameter, you could write the following code:
HttpServletRequest req =
(HttpServletRequest)pageContext.getRequest();
String s = req.getParameter("shares");
if (s == null) {
/* webapp error handler will redirect to error page
* for this exception
*/
throw new BadTradeException("no #shares specified");
}
int ret = -1;
try {
ret = Integer.parseInt(s);
} catch (NumberFormatException e) {
throw new BadTradeException("bad #shares: " + s);
}
if (ret <= 0)
throw new BadTradeException("bad #shares: " + ret);
return ret;
The generated default methods are assumed to throw exceptions. Any exceptions raised during processing will be
handled by the JSP's errorPage, or else by the registered exception-handling pages of the Web Application.
CHAPTER
7 Troubleshooting
The following sections describe several techniques for debugging your JSP files:
n Debugging Information in the Browser
To disable this mechanism, set the verbose attribute to false in the jsp-descriptor element,
http://e-docs.bea.com/wls/docs70/webapp/weblogic_xml.html#jsp-descriptor in the
WebLogic-specific deployment descriptor of your Web Application.
A
action 5-iii
actions 3-viii
administration 2-i
applets 3-xi
application 3-iv
C
cache tag
attributes 4-iv
overview 4-ii
caching 4-ii
character encoding 3-v
compile 3-xiii
compiler 7-ii
compiling 7-ii
config 3-iv
configuration 2-ii
contentType 3-v
custom tags 4-i
and Web Applications 4-ii
cache 4-ii
configuration 4-ii
process 4-vi
custom validator 5-viii
customer support contact information x
D
debugging 7-i
declaration 3-ii
declarations 3-vi
deployment descriptor 2-ii
directive 3-ii
contentType 3-v
taglib 3-v
directives 3-v
documentation, where to find it x
E
encoding 3-v
errors
404 7-i
500 7-ii
503 7-ii
jsp plugin tag 7-ii
page compilation 7-ii
expression 3-ii, 5-iv
expressions 3-vii
F
fieldToValidate 5-iv
form 5-iii, 5-vi
action 5-iii
method 5-iii
name 5-iii
form tag 5-vi
form validation 5-i
G
getParameter() 5-vii
H
headerText 5-iii
HTML
form tag 5-iii
HTML forms 5-vi
HTTP
requests 1-2
I
input tag 5-vii
Apache Jakarta 5-vii
J
Java Plugin 3-xii
JavaBeans 3-viii
JSP administration 2-i, 2-ii
JSP compiler
options 3-xiii
syntax 3-xiii
JSP configuration 2-ii
L
log file 7-ii
M
method 5-iii
N
name 5-iii
O
out 3-iv
P
page 3-iv
pageContext 3-iv
parameters 2-ii
plugin 3-xii
printing product documentation x
process tag
attributes 4-vi
overview 4-vi
R
redirectPage 5-iii
re-displaying value from a form 5-vii
regular expression validation 5-iv
request 3-iii, 3-x
reserved words 3-iii
application 3-iv
config 3-iv
out 3-iv
page 3-iv
pageContext 3-iv
request 3-iii
response 3-iii
session 3-iv
response 3-iii
S
scope 3-x
application 3-x
page 3-x
session 3-x
scriptlet 3-ii
scriptlets 3-vi
serializable 3-xi
Servlet 2.2 specification 1-2
session 3-iv
sessions 3-xi
setting up JSP 2-ii
summary 5-ii
headerText 5-iii
name attribute 5-ii
redirectPage 5-iii
support
technical x
T
taglib 3-v, 4-ii
tags 3-ii, 4-i
custom 4-i
declaration 3-ii
directive 3-ii
scriptlet 3-ii
troubleshooting
browser 7-i
V
validation 5-i
validation tag
form 5-iii
validation tags
summary 5-ii
validator 5-iii
validation tags, using in a JSP 5-iv
validator 5-i, 5-iii
custom 5-viii
errorMessage attribute 5-iv
expression attribute 5-iv
fieldToValidate 5-iv
validatorClass 5-iv
validatorClass 5-iv
verbose 7-i
W
web application 2-ii
web.xml 4-ii
weblogic.xml 2-ii
wl-form 5-iii
wl-summary 5-ii