Showing posts with label custom tag body in jsp. Show all posts
Showing posts with label custom tag body in jsp. Show all posts

Monday, October 11, 2010

JSP Custom Tag with Body


JSP- Custom Tag with Body

Introduction:

Custom tags include jsp components such as text, jsp scriptlets, jsp expression within its body tag are called custom tags with body.

< good:GoodMorning >
suresh goodmoring
< /good:GoodMorning >

The output is the body content is converted into the UpperCase.

We specify custom tag contain body when we are creating TLD file. When we create TLD file, we specify < body-content > element of the TLD as JSP. When we create Custom Tag .we specify < body-content > as empty. Now we are going to create custom tag with body so we specify < body-content > as JSP to indicate that container evaluate the body content of the tag.




Note:
We specify < body-content > as tagdependent, the jsp container should not evaluate the body of the tag but instead pass it to the tag handler for evaluation.



Problem:

< good:GoodMorning >
suresh goodmoring
< /good:GoodMorning >

The output is the body content is converted into the UpperCase.

Procedure:

Step 1:

Create Project named as CustomTagProject (Already we have Created CustomTagProject)

If you are new to Custom Tag, Please refer Custom tag Empty Tag Creation.

Custom Tag – Example For Empty Tag


Step 2:

Create TLD file. Named good.tld

How to create TLD, please refer 

























Important:


No need to include coding into the TLD file. The content of the TLD file will be automatically included into the TLD file when we create Tag handler Class.



Step 3:

            Create Tag Handler Class named as GoodMorning.

Select BodyTagSupport because we are going to create Custom tag with body.





















































Note: we have selected Body Content as JSP.

Step 4:

            Create jsp file named as good.jsp.

< %@page contentType="text/html" pageEncoding="UTF-8"% >
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
http://www.w3.org/TR/html4/loose.dtd >
< %@taglib uri="/WEB-INF/tlds/good" prefix="good" % >
< html >
< head >
< title > JSP good Page < /title >
< /head >
< body >
< h1 > Hello World! < /h1 >
< good:GoodMorning >
sureshkumar
< /good:GoodMorning >
< /body >
< /html >

Step 5:

            Run the good.jsp

Step 6:

            Get Output



Step 7:

            Structure of the CustomTagProject