Abhay Agarwal wrote:I am sorry but i am confused among "tld" file,"tag" file and "custom tag".
Please clarify the difference between all these 3 types/files and when to use which file.
To understand these terms, you need to learn the concept behind tags and their libraries. What are they, and why are they used ?
Tags are defined in TDL files. To give you a start, tags and their libraries reduce the clutter in JSP pages by putting more readable xml tags rather than scriptlets .
For example, I find prettier than
If you concur with me, then lets start by defining own custom tag libraries
(The tag used in the example is that of JSTL core taglib, something Java Engineers have done for us already).
Follow the next steps :
1. First, we define a xml file known by the extension .tld(tag library descriptor).
In this file, we define the structure of our tag, its attributes etc.
2. We put this tld somewhere under WEB-INF and then write Java code to support this tld file.
We compile that code and put it in a place where the Server can find it at runtime (usually WEB-INF/lib)
Therefore, we have moved our Java code from ugly scriptlets in JSP to somewhere in Servlet (remember that all JSPs are compiled into Servlet).
3. Next, we just refer to this .tld from our JSPs specifying its location and giving it a prefix.
That's it! You are free to use your custom tag now. In essence at least. To learn more you will have to explore on your own.
One more thing: Apart from JSTL taglibs and custom taglibs, there are also 3rd party taglibs like the Display Tag that you might find useful.