JSP Tag Libraries: How to Develop Powerful Custom JSP Tags

Overview

Shows HTML and Java programmers how to create and use JSP tag components to perform iterations and access databases, and manipulate EJB's, e-mail systems, Java Beans, and e-commerce applications and WAP that work with cellular phones.

This in-depth tutorial acquaints HTML and Java programmers with JSP tags--Java components that open up JSP development to the everyday content developer (the HTML programmer), and improve code reuse and separation between presentation ...

See more details below
Available through our Marketplace sellers.
Other sellers (Paperback)
  • All (10) from $1.99   
  • New (2) from $36.99   
  • Used (8) from $1.99   
Close
Sort by
Page 1 of 1
Showing All
Note: Marketplace items are not eligible for any BN.com coupons and promotions
$36.99
Seller since 2014

Feedback rating:

(265)

Condition:

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.

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)
$45.00
Seller since 2014

Feedback rating:

(147)

Condition: New
Brand new.

Ships from: acton, MA

Usually ships in 1-2 business days

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

Overview

Shows HTML and Java programmers how to create and use JSP tag components to perform iterations and access databases, and manipulate EJB's, e-mail systems, Java Beans, and e-commerce applications and WAP that work with cellular phones.

This in-depth tutorial acquaints HTML and Java programmers with JSP tags--Java components that open up JSP development to the everyday content developer (the HTML programmer), and improve code reuse and separation between presentation and business logic. It guides the reader through practical JSP applications and demonstrates how tags can be used in the context of e-commerce applications and WAP that work with cellular phones.

Read More Show Less

Editorial Reviews

Booknews
Shows how to develop custom tag libraries with JavaServer Pages (JSP) tags, with sections on the language of tags, basic and advanced techniques, and recommendations for designing, developing, and testing tag libraries. Two full-scale use cases show the effectiveness of tags in the context of commerce and of WAP applications. An appendix describes the syntax of the tag library descriptor. Assumes familiarity with Java, HTML, and JSP. Sachor works for IBM Research. Annotation c. Book News, Inc., Portland, OR (booknews.com)
Read More Show Less

Product Details

  • ISBN-13: 9781930110090
  • Publisher: Manning Publications Company
  • Publication date: 1/28/2001
  • Pages: 623
  • Product dimensions: 7.36 (w) x 9.17 (h) x 1.34 (d)

Meet the Author

Shachor works on high-end applications servers for IBM Research. He was one of the developers of IBM's WebSphere and now also consults and teaches Servlets, JSP, and server-side Java in general.

Chase builds wired and wireless web applications with server-side Java forChalk Creek Software.

Rydin is a server-side ebusiness and intranet developer working as an architect at Cypoint.

Read More Show Less

Read an Excerpt

Chapter 3: Developing your first tags

In this chapter
  • JSP custom tags defined
  • Setting up a development environment
  • Hello World (the tag way)
  • Compiling, deploying, and testing
Thus far we have seen how servlets and JSPs can be used to build a web application. These technologies go some distance toward making web development easier, but do not yet facilitate the separation of Java from HTML in a reusable way. Custom tags make this possible by bundling Java code into concise, HTML-like fragments recognizable by presentation developers. Custom tags are therefore an attractive choice for Java-based web applications and in this chapter, we'll introduce custom tags and walk through examples of their development and use. We'll also look at how to set up a development environment and deploy, test, and troubleshoot tags.

This chapter takes a mountain-top view of custom JSP tags in order to provide a clear, high-level look at the subject's landscape. Later chapters will dive deeper and home in on each of the topics touched upon here. So don't be concerned if the finer details are left for later explanation. The goal now is to jumpstart your tag development and ensure that you're sufficiently comfortable with the basics so that you may start building tags on your own.

3.1 What are JSP custom tags?

At its most fundamental level, a tag is a group of characters read by a program for the purpose of instructing the program to perform an action. In the case of HTML tags, the program reading the tags is a Web browser, and the actions range from painting words or objects on the screen to creating forms for data collection. Custom JSP tags are also interpreted by a program; but, unlike HTML, JSP tags are interpreted on the server side—not client side. The program that interprets custom JSP tags is the runtime engine in your application server (TomCat, JRun, WebLogic, etc.). When the JSP engine encounters a custom tag, it executes Java code that has been specified to go with that tag. Common tasks performed by tag codes include retrieving database values, formatting text, and returning HTML to a browser. Since a tag references some Java code to run when it's encountered, one way to think of a tag is simply as a shorthand notation for a block of code.

Notice in figure 3.1 that when the JSP runtime encounters the tag, it causes a block of Java code to execute and return a message to the client's browser.

3.1.1 Anatomy of a tag

Tags are often structured with a body and/or attributes which are the places where a page author (the user of the tag) can include more information about how the tag should do its job. The following snippet shows the general structure of a tag.
<tagname attributename="attributevalue"
                        otherattributename="otherattributevalue">
Tag's body... can contain about anything.
</tagname>

This syntax should look familiar, since we see it so often in HTML tags, such as:

<font face="Tahoma" size=3">
Tag, you're it!
</font>

Tags can also appear without a body, meaning that the start tag does not have a matching end tag. These "bodyless" tags look like this:

<bodylesstagname attributename="attributevalue"
otherattributename="otherattributevalue"/>

You've probably seen examples of bodyless tags in HTML, such as:

<input type="input" name="body">

Bodyless tags usually represent a certain function, as in the printing of the value of a database field onto the page. Tags often have bodies in order to perform an operation on the content in the body, such as formatting, translating, or processing it in some way.

JSP custom tags are merely Java classes that implement one of two special interfaces. Since tags are standard Java classes, they can interact with, delegate to, or integrate with any other Java code in order to make that functionality available through a tag. For instance, we might have a library of utility classes we've written for composing and sending email, or for accessing a particular database that we'd like to make available to HTML developers. We need build only a few tags that collect the necessary information through attributes and pass this information to our utility classes.

3.1.2 Using a tag in JSP

JSP code that uses email and database tags such as those just mentioned might look something like this:
<html>
I am sending you an email with your account information
<jspx:sendmail server="mail.corp.com"
from="john.doe@corp.com"
to="foo@bar.com"
subject="mail from a tag">
Look at how easy it is to send an email from a tag... here is
your status.
<jspx:dbaccess>
<jspx:wdbcon id="con1"/>
<jspx:wjitdbquery>
select reserves from account where id='<%= userid %>'
</jspx:wjitdbquery>
You have <jspx:wdbshow field="reserves "/>$ in your saving account.
</jspx:dbaccess>
</jspx:sendmail>
</html>

Among the JSP and HTML fragments are special tags prefixed with jspx. Even to the untrained eye, these tags appear to query a database, present the information in the content of an email, and send the message. Notice how the attributes help gather information such as the email sender and subject and the field in the database to display. Also, note how the <jspx:wjitdbquery> tag contains a Structured Query Language (SQL) statement within its body that it uses for the database query. This is a good example of what a JSP using custom tags might look like. Consider how much messier this JSP would look if we had to include all the Java code necessary for creating classes, setting properties, catching exceptions, and so forth.

3.1.3 The tag library descriptor

An important step in creating tags is specifying how they will be used by the JSP runtime that executes them. To properly work with a tag, the runtime must know several things about it, such as what (if any) attributes it has, and whether or not it has a body. This information is used by the runtime to verify that the tag is properly employed by a JSP author and to correctly execute the tag during a request. This crucial information is made available to the runtime engine via a standard XML file called a tag library descriptor (TLD), a key component of the JSP Specification and standard across all products that implement it. How to create a TLD is discussed in section 3.2.4, and covered in greater detail in chapter 5 and appendix B.

3.2 Why tags?

JSP already makes it possible to embed scriptlets (bits of Java code) and JavaBeans in line with HTML content, so why do we need JSP tags? We need them because tags were never intended to offer more functionality than scriptlets, just better packaging. JSP tags were created to improve the separation of program logic and presentation logic; specifically, to abstract Java syntax from HTML.

Scriptlets are not a suitable solution for all web development because most content developers (art designers, HTML developers, and the like) don't know Java and, perhaps, don't care to. Though much Java code can be encapsulated in beans, their usage in a JSP still requires the presentation developer to have a basic knowledge of Java syntax and datatypes in order to be productive. JSP tags form a new "scriptlet-free" and even a completely "Java-free" component model that is adapted perfectly to the JSP environment with its different developer types. If custom tags are properly constructed, they can be of enormous use to HTML developers, even those who have no working knowledge of Java—they won't even have to know they're using it. Tags can reduce or eliminate the number of scriptlets in a JSP application in four ways:

  • A tag is nothing more than a Java component that takes its arguments from attribute and body. Since tags can have attributes and body, any necessary parameters to the tag can be passed within the tag's body or as one of its attributes. No Java code is needed to initialize or set properties on the component.
  • JSP requires a considerable quantity of scriptlets for tasks such as iteration, setting of initial values, and performing conditional HTML. All of these tasks can be cleanly abstracted in a few simple tags.
  • In many cases, a JavaBean component is configured and activated using scriptlets. One can develop a set of JSP tags to perform this configuration and activation without any Java.
  • Tags can implement many utility operations, such as sending email and con-necting to a database, and in this way reduce the number of utility scriptlets needed inside JSP.
The benefits of custom tags also include the creation of a neat abstraction layer between logic and presentation. This abstraction creates an interface that allows Java developers to fix bugs, add features, and change implementation without requiring any changes to the JSPs that include those tags. In short, JSP tags help bring you one step closer to the Holy Grail of web development—true abstraction of presentation and control. For more on the benefits of custom tags, see chapter 15....
Read More Show Less

Table of Contents

Preface ..... xvii
Acknowledgments ..... xix
About this book ..... xxi
Author online ..... xxvi
About the cover illustration ..... xxvii
Part I: The Language of Tags ..... 1
1: The big picture ..... 3
2: Web development with Java ..... 23
3: Developing your first tags ..... 58
4: Custom JSP tag API and life cycle ..... 80
5: Integrating custom tags with the JSP runtime ..... 107
Part II: Basic techniques ..... 127
6: Tag development techniques ..... 129
7: Building a tag library for sending email ..... 195
8: Using JavaBeans with Tags ..... 235
Part III: Advanced Techniques ..... 277
9: Posing conditions with tags ..... 279
10: Iterating with tags ..... 302
11: Database access with tags ..... 340
12: Custom tags and J2EE ..... 385
Part IV: Case studies ..... 443
13: JDBC-driven WebStore ..... 445
14: EJB-driven WAPStore ..... 527
Part V: Design ..... 565
15: JSP tag libraries--tips and tricks ..... 567
A: What is XML? ..... 589
B: The Tag Library Descriptor ..... 597
C: Using the code examples ..... 608
References ..... 615
Index ..... 617
Read More Show Less

Customer Reviews

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

5 Star

(0)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com 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 & Noble.com 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 & Noble.com 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 BN.com 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

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com 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 BN.com. 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)