Mastering Apache Velocity


Designed to work hand-in-hand with Apache Turbine, Struts, and servlets, Velocity is a powerful template language that greatly enhances the developer's ability to customize Web sites. It separates Java code from the Web pages, making a site more maintainable. Because of this, it is a viable alternative to JSPs and PHP and is expected to become the standard template engine. In addition to its use with Struts and Turbine, Velocity can also be used to generate Java and XML source code, XML schemas, HTML templates, ...
See more details below
Available through our Marketplace sellers.
Other sellers (Paperback)
  • All (13) from $1.99   
  • New (3) from $16.80   
  • Used (10) from $1.99   
Sort by
Page 1 of 1
Showing All
Note: Marketplace items are not eligible for any coupons and promotions
Seller since 2008

Feedback rating:



New — never opened or used in original packaging.

Like New — packaging may have been opened. A "Like New" item is suitable to give as a gift.

Very Good — may have minor signs of wear on packaging but item works perfectly and has no damage.

Good — item is in good condition but packaging may have signs of shelf wear/aging or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Acceptable — item is in working order but may show signs of wear such as scratches or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Used — An item that has been opened and may show signs of wear. All specific defects should be noted in the Comments section associated with each item.

Refurbished — A used item that has been renewed or updated and verified to be in proper working condition. Not necessarily completed by the original manufacturer.


Ships from: fallbrook, CA

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
Seller since 2005

Feedback rating:


Condition: New
TIA Somerset, New Jersey, U.S. A 2003 Soft cover New NEW Book, perfect condition, cover/text completely pristine. No physical flaws. FREE TRACKING within the US, and email ... notice when shipped. Normally, books are shipped twice a day, with afternoon USPS pickup, or next morning drop-off at the Post Office. We package on Sunday for shipment first thing Monday morning. Your satisfaction guaranteed. We have multiple copies of most books. Email inquiries are welcomed. Thanks for reading all of our boilerplate. Read more Show Less

Ships from: Garland, TX

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
Seller since 2015

Feedback rating:


Condition: New
Brand New Item.

Ships from: Chatham, NJ

Usually ships in 1-2 business days

  • Canadian
  • International
  • Standard, 48 States
  • Standard (AK, HI)
  • Express, 48 States
  • Express (AK, HI)
Page 1 of 1
Showing All
Sort by
Sending request ...


Designed to work hand-in-hand with Apache Turbine, Struts, and servlets, Velocity is a powerful template language that greatly enhances the developer's ability to customize Web sites. It separates Java code from the Web pages, making a site more maintainable. Because of this, it is a viable alternative to JSPs and PHP and is expected to become the standard template engine. In addition to its use with Struts and Turbine, Velocity can also be used to generate Java and XML source code, XML schemas, HTML templates, and SQL code. Even with all its promise, finding expert instructions on how to properly program with this language has been difficult. This code-intensive tutorial gives you all the tools you'll need. It begins by quickly bringing you up to speed on all of the Velocity fundamentals and the Velocity Template Language. You'll then learn how to apply Velocity in a variety of areas with the help of richly detailed code examples. Additionally, you'll be taken through the steps of building a complete application in order to see how you can utilize all of the techniques and technologies discussed in the book.
Read More Show Less

Product Details

  • ISBN-13: 9780471457947
  • Publisher: Wiley
  • Publication date: 7/3/2003
  • Series: Java Open Source Library
  • Edition number: 1
  • Pages: 372
  • Product dimensions: 7.45 (w) x 9.21 (h) x 0.86 (d)

Read an Excerpt

Mastering Apache Velocity

By Joseph D. Gradecki Jim Cole

John Wiley & Sons

Copyright © 2003

Joseph D. Gradecki Jim Cole
All right reserved.

ISBN: 0-471-45794-9

Chapter One

Web Development Basics

If you remember back almost 10 years ago, you might be able to visualize
how the World Wide Web got its start. Telnet and FTP were among the first
examples of this profound way of communicating. These technologies
weren't directly associated with the Web, but they were certainly a precursor.
Gopher, on the other hand, was a technology that demonstrated how machines
connected on the Internet could be used to share information with people all
across the world.

Soon after gopher was being used to pull information from various places and
sites, the World Wide Web was developed-and the rest is history. This book
explores a part of Web development that has flourished in recent years: the presentation
of dynamic data to the client. Our focus is on a new technology called
Velocity. In this chapter, we provide an overview of the history of Web development
and bring us into the present.

Static Web Pages

It all started with static Web pages; individuals posted photographs of their family
and students posted their lasted research findings. As you would expect, this
was in the early '90s. Amazon was still a concept inbudding entrepreneurs'
heads, and the trading of pictures was basically nonexistent. A page was written
in HTML and had no content produced from a database or other application.
The closest thing to a WYSIWYG GUI for HTML was a yellow legal pad.

The information provided on a static Web page consisted of the content the
page creator wanted to put on it-and nothing more. If users didn't need that
particular information, they had no way to interact with the Web page in order
to bring forward the desired content. The page creator could provide links that
led the user to other pages of information, but the content was still that of the
page creator.

Introducing CGI

CGI (Common Gateway Interface) was one of the more profound technologies
to invade the development of Web pages. Developed in 1993, CGI is a way of
interfacing the Web page with the back-end server responsible for serving
pages to the user. You can see an example of the interface in a search site. If you
go to Yahoo! or Google, you type a topic that you want to learn about into an
edit line typically positioned next to a Submit button. This edit line and button
are part of an HTML form. When you click the Submit button, an action takes
place that is typically a call to another Web page or possibly an application.

When you're using CGI, the action is an application written in a variety of languages,
such as C, Perl, or C++. CGI is not the application itself but serves as
the interface between the form action and the application. When a user clicks
the Submit button, the CGI is responsible for transferring any information from
the HTML form to the server and activating the application on the HTTP server.
The application on the server executes a set of instructions and returns to the
interface a Web page that is displayed to the client browser. Listing 1.1 shows
an example of a simple C CGI application.

int main(int argc, char* argv) {
printf("content-type: text/html\r\n");

Hello World!




Listing 1.1 A simple CGI application in C.

Because CGI applications execute on the Web server, the issue of security is
important. Most servers require that the CGI applications be placed in a directory
called /cgi-bin. The server typically won't allow a CGI application to execute
anywhere than on the server. It is important to note that CGI applications
are built using high-level languages, and were in the beginning quite frustrating
to write until proper libraries came along. At first, these languages weren't typically
used by graphic designers or those who just wanted to put up an interactive
page. As the Web industry started to grow, another option was needed.

Scripting: JSP/ASP/PHP

As you might expect, using CGI and Perl, C, or C++ wasn't something the new
crop of Web designers were going to be able to do. This meant that Web development
companies had to hire both Web designer and software development
talent in order to produce the results the new demanding clients expected. In
addition to this fact, the major players in the software development community,
like Sun and Microsoft, wanted in on the dynamic Web development world. So
they each created a server-side language that could handle getting information
from a back-end system to the client.

Unlike high-level languages that typically have to be compiled into a binary that
will execute on a specific machine, scripting languages are designed to make it
easy to write applications and execute them within an interpreter. The interpreter
is written in a high-level language and executes on the machine where
the HTTP server is located, thus eliminating the need for the Common Gateway

To use the scripting languages, you create a Web page in which the statements
and keywords of the scripting language are embedded in the same file as the
HTML that will be displayed to the user. Listing 1.2 shows an example of such a

Time Example

The time is

Listing 1.2 A scripting language page.

In Listing 1.2, we added some scripting code that displays the current time.
When users browse to this page, they see the current time as supplied by the
HTTP server. So, how does this all occur?

The scripted Web page is placed on the Web server just like any other HTML
page. However, the extension applied to the scripted file is not .html or .htm; it
has an extension like .asp, .jsp, .php, or something else. These extensions are
important because they tell the Web server how the file should be handled
when accessed by a client. If the requested file has an extension other than
.htm, the server sends the file to an interpreter. The system administrator will
have already told the Web server about all possible extensions it might have to
handle and the associated interpreter for the file type.

The interpreter then processes the scripted file and interprets only the scripted
code, leaving all of the HTML intact. During the processing of the file, the
scripted code might place additional HTML into the file as needed. The additional
HTML probably relates to information requested by the user.

At this point, the interpreter returns the final HTML file to the HTTP server,
which in turn provides the page to the client's browser. By using a scripting language,
the Web designer doesn't have to be familiar with high-level programming
languages. Unfortunately, the scripting languages can become complex
and using them may be no more efficient than using CGI and a C++ program.

Future Development

While we are on the subject of scripting languages, it should be noted that there
are some available-like JavaScript, Java, and ActiveX-which can be used and
subsequently compiled by the server for better performance compared to the
interpreted languages. Listing 1.3 shows an example of using Java in an HTML

<%@ page language='java' import='java.sql.*' %>

<% ResultSet rs;
try {

connection = DriverManager.getConnection(
statement = connection.createStatement();

Listing 1.3 Using Java in an HTML page. (continues)

Listing 1.3 Using Java in an HTML page. (continued)

Embedding Java into an HTML page is probably the ultimate in adding dynamic
capabilities to a Web site. Not only do you have to know Java, but an additional
piece of server software is needed to execute the embedded code. An application
server like Resin or Tomcat compiles the Java into a servlet, which is then
executed by the application server when a user browses the HTML page.

In all of the different types of dynamic pages we've discussed so far, the code
for the view and the business logic is intermixed. As you learn in the next chapter,
this intermixing can produce headaches for an organization.

What's Next

In this chapter, we examined the history of Web page development. While many
readers will already be aware of this history, this material is a good background
for those just getting into the Web arena. In the next chapter, we dive into the
methodologies commonly used in the development of Web applications and
focus specifically on the MVC (Model-View-Controller) paradigm.


Excerpted from Mastering Apache Velocity
by Joseph D. Gradecki Jim Cole
Copyright © 2003 by Joseph D. Gradecki Jim Cole.
Excerpted by permission.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Read More Show Less

Table of Contents

About the Authors
Pt. I Introduction to Velocity and MVC
Ch. 1 Web Development Basics 1
Ch. 2 MVC Fundamentals 7
Ch. 3 Introduction to Velocity 17
Pt. II Velocity Basics
Ch. 4 Installing Velocity 23
Ch. 5 Building a Hello World Example 37
Ch. 6 Understanding Templates and Context 45
Ch. 7 Exploring References 57
Ch. 8 Using Directives 77
Ch. 9 Introducing Velocimacros 109
Ch. 10 Taking Control of Velocity 119
Pt. III Developing with Velocity
Ch. 11 Velocity, XML, and Anakia 139
Ch. 12 Using Velocity with Servlets 155
Ch. 13 Velocity and Internationalization 185
Ch. 14 Using Velocity and Turbine 195
Ch. 15 Using Velocity and Maverick 223
Ch. 16 Velocity IDEs 247
Ch. 17 Using Velocity and Struts 255
Ch. 18 The Hotel Reservation Velocity Application 269
Ch. 19 Using JSP and Velocity 299
Ch. 20 DVSL and Velocity 305
Pt. IV References
App. A The Velocity Specification 315
App. B Velocity Sites 343
Index 347
Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)