• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Custom tags in jsp

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sir,
I want to know how to write custom tags in jsp and how to define tld files and use them.I want complete explanation with an example code.

 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're in luck - a good tutorial on tag libraries is available.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Siva It is very easy to use the custom tags in jsp.

The main objective of custom tags is to completly remove the java code from the jsp.
the jstl,el,scriptlet.....etc may not completely remove the java code from the jsp.
by using custom tags we can remove the java code.

follow the bellow lines.

Required components to develop the custom tags.
1)TagHandler class.------>it is simple java class and it contains entire our own custom tag logic.
2)tld file------------------->it contains the mapping information b/w TagHandler class and the jsp file
3)jsp file with taglib directive.---> it is a simple jsp file contains your own custom tags.

ex for custom tag:--
<jrntr:iliyana/>
if this tag is encounterd by jsp engine internally tag handler class will be executed and the logic will be executed.
simple ex for custom tag:

test.jsp


web.xml



mytld.tld



CustomTagDemo.java to compile this class you need to set the class path jsp-api.jar
here if you understand the code ok fine,otherwise just understand the flow of the application.






******used tomcat 5.5 version.(if you use tocat6 then change the <taglib version="2.1" > in mytld.tld file

folder structure
1)test.jsp----inside context root
2)mytld.tld---inside WEB-INF
3)web.xml---inside WEB-INF
4)CustomTagDemo--inside classes

flow of the above application.

*when ever the jsp engine encounters the custom tag it will find out the prefix.
*with this prefix it can find out the proper taglib directive.
*after that it will find out the uri.
*it takes that uri and directly goes to the web.xml in that we configured proper tld file.
*again it goes to tld file and find the logical name(here the logical name is iliyana <jrntr:iliyana/>)
*if it finds iliyana it can executes the corresponding TagHandlerClass.
*in that tag handler class what ever the logic is there that can be executes.

thats it cinima got completed.



cheers i hope you got some minimum idea about custom tags with this explanation.

By,
Praneeth.
JavaMirchi.



 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Praneeth Thiruveedhula, please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic