Signup/Sign In

JSP Custom Tag

When EL and Standard Action elements aren't enough to remove scriptlet code from your JSP Page, you can use Custom Tags. Custom tags are nothing but user-defined tags.

Custom tags are an excellent way to abstract the complexity of business logic from the presentation of Web pages in a way that is easy for the Web author to use and control. It also allows for reusability as custom tags can be used again and again.

Format of JSP Custom tag

The format of a custom tag can either be empty, called an Empty tag, or can contain a body, called a Body tag. The number of attributes that a tag will accept depends on the implementation of the Tag Handler class.

Syntax for an Empty Tag is:

<tagLibraryPrefix:customTagName attribute1="attributeName" 
    attribute2="attributeName" ... />

The Syntax for a Custom Body Tag is :

<tagLibraryPrefix:customTagName attribute1="attributeName" 
    attribute2="attributeName" ... />
  < --Body of custom tag-- >

Creating custom tags is considered as a very good practice in JSP world. Always try to create and use your own custom tags from frequently used operations in your JSP application. Let's move to the next lesson and study how to create a Custom tag.