iteration over uniform and hierarchical collections (such as menus for navigation)
presenting content based upon security roles
locating information from the model (in MVC)
locating information from an EJB layer (in smaller apps)
checking values of cookies
generating HTML controls such as drop downs and lists from collections of JavaBeans
Basically, tags are great for any type of presentation related logic that you would normally code with scriptlets. There are many, many more uses but I hope that's useful for starters... Simon p.s. check out the sample chapters from Professional JSP Tag Libraries for some more examples [ July 18, 2002: Message edited by: Simon Brown ]
For me the "bottom line" with custom tags is that they are another way of getting code out of scriptlets and into proper Java. I have been burned too many times with bugs and even compilation errors in scriptlets which don't show up until long after a web application has been deployed. Now I hate seeing code in JSPs. Custom Tags allow all that yucky scriptlet code to be simply moved to regular Java classes, where it can be compiled and tested before deployment rather than waiting for the live system to fail. Also, because they are well-formed XML, you can use XSLT to style your JSPs. Bonus!
Is there something that can only be done by using Custom tags ? Is the primary objective of custom tags separation of Java code from the HTML ?? Varun Narula
posted 18 years ago
Is the primary objective of custom tags separation of Java code from the HTML ?? Yes, and all the side benefits that gives: compilation and testing of code before deployment, more readable JSP source, easier re-use of tag code etc. etc. I can't emphasize this enough, putting raw Java scriptlet code in JSP pages is bad. You should feel naughty when you do it, and move the code out to something more reliable, readable, reusable and testable as soon as you can.