What is the use of TAG Libraries in JSP and why we are using it?
I am new to JSP and i've come accross Tag libraries, Please give me some detail explaination of tag librarie开发者_C百科s, where and what type of application we should use that?
Thanks in advancve
Tag Libraries are used based upon your requirement, say, when you need more than what can be done using EL and standard actions. The tag libraries contain custom tags that can be used as per your need and you can even create your own custom tags(that is a big process & requires you write the java code that is run when you use your customized tag in the JSP), in most cases, the available tags in the JSTL would be sufficient.
Stepping a step backward, tags are used in JSPs in order to separate the scripts(java code) from the jsp pages, ie, script-free pages help in maintainability as presentation is separated from logic, and it even helps web page designers who dont know java to beautify the jsp pages without them having to deal with the java code embedded in the jsp pages.
I suggest you read 'Head First Servlets & JSP' for a better understanding of the entire process.
Tag libraries allow a cleaner separation between the look-and-feel of your application and its logic, compared to the original scriptlet syntax offered by JSP. Replacing scriptlets with custom tags eliminates the awkward confusion of imperative Java and declarative markup that used to be common in JSPs.
In an ideal world, web designers would be able to edit JSP files using a combination of standard markup and custom tags. Common markup patterns can be factored out into tag files; if they need something that requires new logic, a programmer can implement a tag class for them.
There are two ways to implement a tag library: tag files, and tag classes. Tag files use a syntax that is nearly the same as JSP, but can be parameterized with attributes in the tag. Tag classes are normal Java classes that implement a special interface, and bundled with a Tag Library Descriptor—an XML file that describes the tag name, attributes, and implementation class.
Most Java web frameworks today come with a custom tag library that helps developers utilize the features of the framework more easily. Other tag libraries, like JSTL, provide functionality that is useful in almost any application, and can be used in conjunction with any framework.
精彩评论