The Differences Between Simple and Classic Tags in JSP
By: Grenfel in JSP Tutorials on 2007-10-06
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.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
- Data Science
- React Native
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews
Show a calendar for user input in JSP
Encrypting Passwords in Tomcat using Servlets
Steps to get a Free SSL certificate for your Tomcat
JSP Tags for SQL to connect to a database
LifecycleException: service.getName(): "Catalina"; Protocol handler start failed: `java.net.BindException: Permission denied <null>:80
Uploading a file to a server using JSP
Uploading an Image to a Database using JSP
A JSP page that gets properties from a bean
Querying Data with the JSTL in JSP