Files Prepare Run Troubleshooting Related Topics
Simple tags are a new JSP 2.0 feature. They present a much simpler invocation protocol than do classic tag handlers. A simple tag handler is represented in Java by a class which implements the SimpleTag interface. In addition to being simpler to work with, simple tag extensions do not directly rely on any servlet APIs, which allows for potential future integration with other technologies. This is facilitated by the JspContext class, which PageContext extends. JspContext provides generic services such as storing the JspWriter and keeping track of scoped attributes, whereas PageContext has functionality specific to serving JSPs in the context of servlets. Whereas the Tag interface relies on PageContext, Simple tags only rely on JspContext. The body of a Simple Tag, if present, is translated into a JSP fragment and passed to the setJspBody method. The tag can then execute the fragment as many times as needed.
Unlike classic tag handlers, the SimpleTag interface does not extend Tag. Instead of supporting doStartTag() and doEndTag(), the SimpleTag interface provides a simple doTag() method, which is called once and only once for any given tag invocation. All tag logic, iteration, body evaluations, and so on are performed in this single method. Thus, simple tag handlers have the equivalent power of a BodyTag, but with a much simpler lifecycle and interface. To support body content, the setJspBody() method is provided. The container invokes the setJspBody() method with a JspFragment object encapsulating the body of the tag. The tag handler implementation can call invoke() on that fragment to evaluate the body. The SimpleTagSupport convenience class provides getJspBody() and other useful methods to make this even easier.
The example demonstrates the Simple Tag API. It uses TagSupport to iterate through a collection. It also uses BodyTagSupport and TryCatchFinally to access data in a database.
The IteratorTag.java file demonstrates how to extend the JSP 1.2 Simple Tag API to iterate thru a collection, while the ExecuteSql.java file demonstrates how to extend the JSP 1.2 Simple Tag API to manipulate data located in a database.
Directory Location:
BEA_HOME/wlserver_10.3/samples/server/examples/webapp/jsp/tags/simple/
(where BEA_HOME is the directory containing your WebLogic Server installation)
File Click source files to view code. |
Description |
|---|---|
| application.xml | The Java EE standard enterprise application deployment descriptor. |
| build.xml | Ant build file that contains targets for building and running the example. |
| ExamplesFooter.jsp | Java Server Page containing the Example Footer. |
| ExamplesHeader.jsp | Java Server Page containing the Example Header. |
| ExecuteSql.java | This class demonstrates extend the JSP 1.2 Simple Tag API to manipulate data located in a database. |
| IteratorTag.java | This class demonstrates extend the JSP 1.2 Simple Tag API to iterate thru a collection. |
| SimpleTag.jsp | Java Server Page containing the Simple Tag. |
| simpleTag.tld | The Simple Tag Library Descriptor. |
| web.xml | The Java EE standard Web application deployment descriptor. |
| weblogic.xml | The WebLogic Server-specific Web application deployment descriptor. |
| weblogic-application.xml | The WebLogic Server-specific enterprise application deployment descriptor. |
Before working with this example:
No special configuration is required for this example
To build the example, follow these steps:
Change to the SAMPLES_HOME\server\examples\src\examples\webapp\jsp\tags\simple directory,
where SAMPLES_HOME refers
to the main WebLogic Server examples
directory, such as d:\bea\wlserver_10.3\samples.
ant buildant deploy wl_server domain
of your WebLogic Server installation.
The Ant command uses the build.xml file, located in the SAMPLES_HOME\server\examples\src\examples\webapp\jsp\tags\simple directory, to build the example.
Running the build script builds the EJB in split development directory format
where compiled and generated classes are placed in SAMPLES_HOME\server\examples\build\jspSimpleTagEar and non-compiled files remain within the source directory
of the example. For more information on split development directory, see Developing WebLogic Server Applications.
To run the example, follow these steps:
SAMPLES_HOME\server\examples\src\examples\webapp\jsp\tags\simple):
prompt> ant run
This command executes the build.xml run target, which opens your default browser to the following URL:
http://localhost:port/jsp_simpleTag/SimpleTag.jsp
where
localhost refers to the machine on which WebLogic Server is running
port refers to port on which WebLogic Server is listening
Note: To execute a Web-based example, you can manually open the browser to the appropriate URL or you can use the build.xml run target by entering ant run at the command prompt. The latter is the Oracle suggested method for running this example.
Iterating over a collection using custom iterate tag...
Element is Apples
Element is Oranges
Element is Grapes
Element is Kiwis
Element is Strawberries
You will also see a custom SQL tag Query, with results displayed in a table.
(Internet connection required.)
Copyright © 1996, 2008, Oracle and/or its affiliates. All Rights Reserved.