Using a JSTL in JRun 4
by Nick Calenda Senior Product Support Engineer May 2002
Copyright © 2002 Macromedia, Inc. All rights reserved. The information contained in this document represents the current view of Macromedia on the issue discussed as of the date of publication. Because Macromedia must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Macromedia, and Macromedia cannot guarantee the accuracy of any information presented after the date of publication. This white paper is for information purposes only. MACROMEDIA MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT. Macromedia may have patents, patent applications, trademark, copyright or other intellectual property rights covering the subject matter of this document. Except as expressly provided in any written license agreement from Macromedia, the furnishing of this document does not give you any license to these patents, trademarks, copyrights or other intellectual property. Add Life to the Web™, Afterburner™, Aftershock™, Andromedia®, Allaire® , Animation PowerPack™, Aria®, Attain™, Authorware®, Authorware Star®, Backstage™, Bright Tiger®, Clustercats® , ColdFusion®, Design In Motion™, Director®, Dream Templates™, Dreamweaver®, Drumbeat 2000™, EDJE®, EJIPT®, Extreme 3D®, Fireworks®, Flash™, Fontographer®, FreeHand®, Generator™, HomeSite™, JFusion™, JRun™, Kawa™ , Know Your Site®, Knowledge Objects™, Knowledge Stream™, Knowledge Track™, LikeMinds™o Lingo™, Live Effects™, MacRecorder Logo and Design®, Macromedia®, Macromedia Action!®, Macromedia Flash™, Macromedia M Logo and Design™, Macromedia Spectra™ , Macromedia xRes Logo and Design®, MacroModel®, Made with Macromedia™, Made with Macromedia Logo and Design®, MAGIC Logo and Design™, Mediamaker®, Movie Critic®, Open Sesame! ™ , Roundtrip®, Roundtrip HTML™, Shockwave®, Sitespring™ , SoundEdit™, Titlemaker™, UltraDev™, Web Design 101™, what the web can be™, Xtra™ are either trademarks or registered trademarks of Macromedia, Inc. in the United States and/or other countries. The names of actual companies and products mentioned herein may be the trademarks of their respective owners. Macromedia, Inc. 600 Townsend Street San Francisco, CA 94103 415–252–2000
Using a JSTL in JRun 4
Contents
What is a JSTL? ................................................................................................................ 1 Where to find the JSTL tags ......................................................................................................................... 1 Installing a JSTL in JRun 4........................................................................................................................... 1 Deploying the request-doc.war & the request-examples.war files in JRun 4 ............................................... 2 Testing the installation of the request JSTL ................................................................................................. 3 Conclusion ........................................................................................................................ 4
May 2002
Page iii
Using a JSTL in JRun 4 What is a JSTL?
JRun 4 has full J2EE (Java 2 Platform, Enterprise Edition) 1.3 compatibility. One advantage of this is JavaServer Pages (JSP) Standard Tag Libraries (JSTLs), which only run on J2EE-compatible application servers.In JRun 4, you can build your new JSP application using JSTL tags, or deploy your existing application. This document provides information on JSTLs and how to deploy them in JRun 4.
What is a JSTL?
A JavaServer Pages (JSP) Standard Tag Library (JSTL) encapsulates core functionality common to many JSP applications. The main purpose of a JSTL is to standardize core functionality most commonly used in many JSP applications to enable them to function on all JSP containers. In addition, JSTLs make the task of writing core functionality easier. For example, JSTLs support common, structural tasks (including iteration and conditionals), and tags for manipulating XML documents, internationalization, and accessing databases using SQL. A JSTL also provides a framework for integrating custom tags you might have already developed. When using JRun 4, in current and future projects, Macromedia recommends you use a JSTL instead of the JRun tags that shipped in earlier releases of JRun. The following are some reasons why a JSTL is ideal: It helps to separate business logic from presentation. It makes developing JSPs that much easier and faster, because it has a much smaller learning curve for developing core functionality. It is portable. JSTLs will run on all JSP containers compatible with the JSP API Specification, version 1.1 or later.
Where to find the JSTL tags
The Java Community Process JSR-052 Expert Group will host the JSTL reference implementation at Jakarta Taglibs. To download the latest implementation of JSTL, visit The Jakarta Project at http://jakarta.apache.org/taglibs/. Look for the download "Entire Binary Distribution" link on the left navigation bar. To obtain the specification, visit the JSR-052 A Standard Tag Library for JavaServer Pages™ page.
Installing a JSTL in JRun 4
After you download the entire binary distribution, select the ones that you want to use. You download the entire distribution, but you only are able to install the JSTLs that you will need. The Jakarta Taglibs include a folder for each tag library; the folder name is the same as the name of the tag. For example, the request folder is also the name of the request taglib. The request folder contains the associated files needed to install the request JSTL. Each folder contains the tld file, a JAR file, documentation, and examples.
May 2002
Page 1
Using a JSTL in JRun 4 What is a JSTL?
The example in this section is for the request taglib, but the same instructions apply to all taglibs. Simply replace “request” with the taglib name you need. The following is a list of all the files in the jakarta-taglibs\request folder from the Entire Binary Distribution:
File Description
request.tld request.jar requestdoc.war
The tag library descriptor file for this custom tag library. A JAR file containing the Java classes and associated resources for this custom tag library. A war file you can deploy that contains documentation that describes how to use the tags in this custom tag library. This web application can be deployed and executed on any servlet container that is compatible with the Servlet API Specification, version 2.2 or later. A war file you can deploy that uses examples to demonstrate how to use the tag library. This web application can be deployed and executed on any servlet container that is compatible with the Servlet API Specification, version 2.2 or later.
requestexamples.war
Especially if it is your first time using the tag(s), start out by deploying both the {taglib}-doc.war and {taglib}-examples.war files. The documentation application and the examples application can be very helpful when you learn how to use each tag.
Deploying the request-doc.war & the request-examples.war files in JRun 4
Before you deploy both war files in JRun 4, decide in which server you want these applications to run. The example in the following table uses the default server, which runs on port 8101:
WAR file URL
requestdoc.war requestexamples.war
http://localhost:8101/request-doc (if the server is using port 8101) http://localhost:8101/request-examples (if the server is using port 8101)
To deploy both the request-doc.war file and the request-examples.war file, drop the files into the {JRun4.rootDir}/servers/default folder. JRun 4 sees these two applications and automatically deploys them. If you turned off hot deployment in JRun 4, then the server deploys both applications on restart. After they are deployed, you can request the applications by using the file name of the war file as the Context Root. To fully comprehend what the tag does and how to use it, read the documentation and take a look at the examples mentioned previously. To install the request taglib into an existing or new application in JRun 4:
1 2 3
Copy the request.jar file into the WEB-INF/lib folder. Copy the request.tld file into the WEB-INF folder. Add the request taglib element to your web.xml file, as follows:
http://jakarta.apache.org/taglibs/request
Page 2
May 2002
Using a JSTL in JRun 4 What is a JSTL?
/WEB-INF/request.tld
4
Add a page directive at the top of each JSP page where you are going to use the request tag, as follows:
<%@ taglib uri="http://jakarta.apache.org/taglibs/request" prefix="req" %>
This example only uses one taglib. If you have two or more tags, add them in the page directive as well. The prefix "req" is the prefix used to call the request taglib within your JSP. You can name the prefix anything. The following code example shows how it would look in a JSP page:
User-Agent=
Note: If hot deployment is active in JRun 4, the JSTL tags deploy automatically. If you have this feature turned off, you need to restart the server before using the JSTL tags.
Testing the installation of the request JSTL
Now that the request JSTL is installed on JRun 4, you need to test it. Using the following JSP page, save it to the application root folder and request the page:
<%@ taglib uri=http://jakarta.apache.org/taglibs/request prefix="req" %>
Request JSTL Test Page
See if User-Agent Header exists, as follows:
User-Agent=
If you see something similar to the following in your browser, you have the request JSTL installed correctly. (Keep in mind that it will display your User-Agent information.)
See if User-Agent Header exists User-Agent=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 4.0)
May 2002
Page 3
Using a JSTL in JRun 4 Conclusion
Conclusion
Using JSTL tags in your application can save you a lot of development time because JSTL tags are easy for designers to use, they promote code sharing, and, most importantly, they are portable across application servers. The next time you have to build a JSP application or update your current application, check out the Jakarta Taglibs for the latest tags. (As this project evolves, new tags will be added periodically.)
Page 4
May 2002