The Differences Between Simple and Classic Tags in JSP

By: Grenfel Emailed: 1788 times Printed: 2614 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

There are several key differences between simple and classic tags. Let’s take a quick look at each in turn and evaluate what it means to you as a tag developer.

The Tag Handler Interface

The fundamental difference between simple and classic tags is the way in which the tag handler class is implemented. When you’re using simple tags, any tag handlers you build must implement the javax.servlet.jsp.tagext.SimpleTag interface. When you’re using classic tags, however, the tag handlers must implement the javax.servlet.jsp.tagext.Tag interface or, as you’ll see in this chapter, one of its subinterfaces.

For you as a developer, this means you need to learn a slightly different programming model. For example, when using simple tags, all of the functionality to be encapsulated within the tag is defined within the doTag() method. When using classic tags, there are two methods you must implement: doStartTag() and doEndTag().

Feedback from tag developers over the past couple of years has been mixed, and many people find the concepts employed by classic tag handlers confusing. Therefore, the interface has been simplified and simple tags are the result of this process.

The Tag Life Cycle

Another key, though often neglected, difference relates to the tag life cycle. With simple tags, an instance of the tag handler class is created when needed and that instance is used to serve only a single invocation of a custom tag. In other words, a unique tag handler instance is created for each usage of a simple tag on a page.

With classic tags, this may or may not be the case because the JSP specification enables container vendors to optionally improve classic tag performance by pooling and reusing tag handler instances. This means that, for example, a single tag handler instance could be created and reused to service all invocations of that custom tag per page. The rules around reuse are fairly complicated, and to make matters worse, JSP container vendors don’t always choose to implement this optional piece of the specification. Therefore, if you’re using classic tags, you must be aware of whether your container pools and reuses tag handler instances.

The problems that arise between different JSP containers is another reason simple tags were introduced, and it’s another area in which the complexity associated with developing them has been reduced. The downside is that there may be times when you’d like tag instances pooled and reused. For example, your tag might acquire some expensive resource when it is created. In this example, it makes sense to take advantage of any performance benefits that the container may provide. In many scenarios, however, this just isn’t an issue and simple tags are more than adequate.

JSP Home | All JSP Tutorials | Latest JSP Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.

Bookmark and Share


Be the first one to add a comment

Your name (required):

Your email(required, will not be shown to the public):

Your sites URL (optional):

Your comments:

More Tutorials by Grenfel
Verifying a Signed JAR File example
Bitwise and Bit Shift Operators example in Java
JavaBeans Basic Concepts
The Differences Between Simple and Classic Tags in JSP
Bitwise Logical Operators in C
DispatchAction in Struts
union example program in C
Comparison operators in JSP
Basics of Structures in C
register Variables in C
Struts and Tiles - Steps to use Struts and Tiles
The if else statement in C
Character Counting sample program in C
Installing JSF
cin.ignore() in C++

More Tutorials in JSP
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: ` Permission denied <null>:80
JSP Alert Example
JSP CheckBox Example
Uploading an Image to a Database using JSP
Uploading a file to a server using JSP
A JSP page that gets properties from a bean
The page Directive in JSP
The taglib, tag, include, attribute and the variable Directive in JSP
Declarations in JSP
Scriptlets and Expressions in JSP
Tag Libraries in JSP
The Request Object in JSP
The Response Object in JSP
The Out Object in JSP
The Session Object in JSP

More Latest News
Most Viewed Articles (in JSP )
JSP Example to connect to MS SQL database and retrieve records
What are the different scopes in JSP?
JSP CheckBox Example
JSP Alert Example
Comparison operators in JSP
Sending Email using JSP
Uploading an Image to a Database using JSP
Arithmetic Evaluation Using the Expression Language in JSP
The Advantages of JSP
Writing your first JSP page
Uploading a file to a server using JSP
The Request Object in JSP
Disabling Scriptlets in JSP using web.xml
Deploying an Individual JSP on Tomcat
Automatically Refreshing a JSP
Most Emailed Articles (in JSP)
The Tag Life Cycle with Attributes in JSP
Calling JSP from a batch file
JSP Program for display Date
Sessions in JSP
Simple HTML-Building Utilities
Handling Events
Using a DataSource from WebLogic in a JSP
The JSP Program running first Time.
Declaring variable in JSP
The Advantages of JSP
Password Object
Retrieving a Portion of a String
Automatically Including Preludes and Codas in JSP
The Differences Between Simple and Classic Tags in JSP