| By Anatoly Krivitsky | Article Rating: |
|
| May 5, 2005 04:00 PM EDT | Reads: |
21,397 |
Tomcat binaries can be downloaded from http://jakarta.apache.org/site/binindex.cgi.
The latest Tomcat release is Tomcat 5. The differences between versions aren't important to this article. We assume you'll use a Tomcat 5 servlet container.
The installations described here are straightforward; no additional comments are needed.
From here on out for brevity's sake it's assumed you're using a Windows XP Pro box. What to do with a Linux box is pretty much the same and will also be described below.
To work with JSF and Tomcat 5 you need to download the JSF reference implemetation JARs that are zipped in a file jsf-1_1.zip from Sun at http://java.sun.com/j2ee/javaserverfaces/download.html.
Unzip it in a directory where a set of subdirectories will be created. Suppose, for a moment, that you downloaded jsf-1_1.zip in C:\Documents and Settings\My Documents\jsf 1.1. A set of subdirectories in C:\Documents and Settings\My Documents\jsf 1.1\jsf-1_1 will be created when your unzip the file.
You will need the following files from C:\Documents and Settings\My Documents\jsf 1.1\jsf-1_1\lib for your Web application:
commons-beanutils.jar
commons-collections.jar
commons-digester.jar
commons-logging.jar
jsf-api.jar
jsf-impl.jar
jstl.jar
You will also need a standard.jar file that can be downloaded from http://archive.apache.org/dist/jakarta/taglibs/ standard/binaries/jakarta-taglibs-standard-1.0.1.zip. You may want to use another location for more recent version. Unzip the downloaded .zip file in a directory and locate standard.jar. All these jars should be copied under {Tomcat Home}\ webapps\{Directory with Your Application}\[auxiliary directory\]WEB-INF\lib. Usually {} brackets enclose mandatory values, while [] brackets enclose values that can be omitted. Tomcat Home is a full path to the directory that contains Tomcat. If Tomcat Home is C:\jakarta-tomcat-5.0.19, the directory with your application is DwhetSF, the auxiliary directory is WebContent, which will be written as:
C:\jakarta-tomcat-5.0.19\webapps\DwhetSF\WebContent\WEB-INF\lib
Configuration
server.xmlThough it's possible to run JSF-based Web applications for remote benchmarking without changing Tomcat's server.xml, I strongly recommend that you change it when you're developing on your local box and ask your provider to change it on the server to make it more convenient to do other things (like working with databases using JNDI). So it's important to have experience related to working with server.xml.
The file is located under {Tomcat Home}\conf. For remote benchmark applications the only change you need to make in server.xml is to insert this line tag in the file:
<Context path="/{Directory with Your Application}"
reloadable="true" docBase="{Tomcat Home}\ webapps\
{Directory with Your Application}[\auxiliary directory]" debug="0" />
In our example above notation will be written as:
<Context path="/DwhetSF" reloadable="true"
docBase="C:\jakarta-tomcat-5.0.19\webapps\DwhetSF\WebContent" debug="0" />.
This tag should be inserted after:
<Logger className="org.apache.catalina.logger.FileLogger" directory="logs"
prefix="localhost_log." suffix=".txt" timestamp="true"/> tag and before </Host> tag.
faces-config.xml and web.xml
These files should be located under {Tomcat Home}\ webapps\{Directory with Your Application}\[auxiliary directory\]WEB-INF\.
The standard contents of web.xml can be used in most of your development. I recommend the following sample of web.xml: www.javaranch.com/newsletter/200404/files/web.xml.html
You will need to change faces-config.xml for each new application. For remote benchmarking, faces-config.xml can be written as shown in Listing 1. The listing will be commented in the next sections.
Property Files
These files aren't mandatory but can be useful for various messages. For brevity's sake, the property file related to the application is omitted.
JSPs
As you can see in Listing 1 we need input.jsp and response.jsp. The first page is for user input handling and validation; the second one is used for remote benchmarking output. The connections with the managed bean described below are provided by the JSF Expression Language expressions that begin with the symbols #{. The JSPs are shown in Listings 2 and 3.
An auxiliary simple index.jsp is used to point the browser at input.jsp. Mentioned pointing is provided by the tag <jsp:forward page="faces/pages/input.jsp" />. The index.jsp is located under {Tomcat Home}\ webapps\{Directory with Your Application}\[auxiliary directory\]
Managed Bean
This bean provides the main computations for remote benchmarking. It gets user input from input.jsp and provides information to be used in response.jsp. The source code is given in Listing 4.
You can use any IDE that supports J2EE 1.4 or even Ant (the Apache tool) and a command-line compiler to build the class from the source code. The built class should be put under {Tomcat Home}\ webapps\{Directory with Your Application}\[auxiliary directory\]WEB-INF\classes\{package name}\
How to Test
To test you need to start Tomcat and point your browser at http://localhost:8080/{Directory with Your Application}/.
Figure 1 shows the input of the application and Figure 2 shows the results.
How to Deploy on a Remote Server
After you will test the application on your local box, you'll want to deploy it. Ask you provider if you can deploy .war files. If the answer is yes, create a .war file and ftp it in the appropriate directory on the remote server.
If you can't deploy .war files then you need to ftp class, jsps, the configuration, and, if needed, property files. Submit the changes in server.xml to your provider or do it yourself if you're allowed.
Conclusion
This article offers a simple but powerful JSF- and servlet-based Web application for remote benchmarking. You should now be able to do remote benchmarking and develop simple- to medium-level JSF- and servlet-based Web applications. I strongly recommend that you check the Web sites mentioned here for updates.References
Published May 5, 2005 Reads 21,397
Copyright © 2005 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Anatoly Krivitsky
Anatoly Krivitsky has a PhD in computer science and has more than 24 years of working experience in the IT field. He's the author of 20 published papers and books and five patents. For more information, please visit http://www.myjavaserver.com/~akrivitsky/index.html.
- Kindle 2 vs Nook
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- Confessions of a Ulitzer Addict
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- It's the Java vs. C++ Shootout Revisited!
- Cloud Computing Can Revitalize Your Career as Software Developer
- IBM Could "Reinvent" Java: Mills
- Oracle & Cloud Computing: Exclusive Q&A with SVP Richard Sarwal
- A Brief History of Cloud Computing
- Kindle 2 vs Nook
- Cloud CEOs, CTOs & SVPs to Speak at 4th International Cloud Computing Expo
- Why IBM’s Server Chief Got Busted
- Is Cloud Computing Like Teenage Sex?
- Industry Experts Discuss the State of Cloud Computing
- Performance Tuning Essentials for Java
- The Difference Between Web Hosting and Cloud Computing
- Cloud Computing Expo: Exclusive Q&A with Yahoo! SVP Cloud Computing
- Ajax in RichFaces 3.3, JSF 2 and RichFaces 4
- Confessions of a Ulitzer Addict
- My Thoughts on Ulitzer
- Tactical Cloud Computing Panel at 1st Annual GovIT Expo
- A Cup of AJAX? Nay, Just Regular Java Please
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- JavaServer Faces (JSF) vs Struts
- Rich Internet Applications with Adobe Flex 2 and Java
- Java vs C++ "Shootout" Revisited
- Bean-Managed Persistence Using a Proxy List
- Reporting Made Easy with JasperReports and Hibernate
- Creating a Pet Store Application with JavaServer Faces, Spring, and Hibernate
- What's New in Eclipse?
- Why Do 'Cool Kids' Choose Ruby or PHP to Build Websites Instead of Java?
- i-Technology Predictions for 2007: Where's It All Headed?

































