61. How to create JSP custom tags?
- Step 1: Create a tag handler class with the custom logic.
- Step 2: Create a tag library descriptor(TLD) file and configure the custom handler.
- Step 3: Import the custom tag library in jsp using taglib directive.
- Step 4: Start using the custom tag in a JSP page.
Tag handler is a java class that holds the logic of the custom tag.
- Tag interface
- BodyTag interface
- TagSupport class
- BodyTagSupport class
- SimpleTagSupport class
The SimpleTagSupport class is the base class intended to be used for developing tag handler. The SimpleTagSupport class implements the SimpleTag interface and defines API’s which can be overridden by the custom tag handlers.
66. What is a TLD file?
TLD stands for Tag Library Descriptor. TLD file is an XML file containing details of all the tags being created. It should be placed in web-inf directory.
67. Why attributes are used with JSP custom tag and mention the steps for adding attributes to a tag?
Attributes are used to modify the behavior of a tag. Following are the steps for adding attributes to a tag:
- Step 1: Add an attribute as a property to the tag handler.
- Step 2: Create setter method for the property following the bean setter naming convention.
- Step 3: Add the attribute requirement specification in the TLD file.
68. Explain JSP custom tag with body using an example?
We can create JSP custom tag with body. The tag handlers can access the tag body and can do some processing on the body content. For example, If we want some text to be always capitalized we can place it inside a custom tag body whose handler can read the text and capitalize and print it.
69. Mention the steps in creating a custom tag with body?
- Step 1: Create a tag handler extending the SimpleTagSupport class.
- Step 2: Override the doTag() method.
- Step 3: Develop the logic in the doTag() method to read and process the text content.
- Step 4: Specify the body-content entry in the TLD file.
70. What happens when body-content is set as scriptless in TLD file?
The body-content is set as scriptless which means the body can contain static text, EL expressions and custom tags. Scripting elements are not allowed.
71. What is JSTL?
The Java Server pages Standard Tag Library (JSTL) is a collection of useful tags which encapsulates some useful functionality widely used in many JSP applications.
72. What are the functionalities that JSTL implements?
JSTL has some common functionalities implemented such as iteration, conditional statements, tags for manipulating XML documents, internationalization tags and SQL tags.
73. What are the types of JSTL tags?
Based on the functionality there are five categories of JSTL tags:
- Core tags
- Formatting tags
- SQL tags
- XML tags
- JSTL functions
74. What is core tag?
Core tag specify several actions such as displaying content based on a condition, manipulating collections and managing URL’s such as redirecting to a different page. It is used to do more common actions in easier and effective way whereby minimizing the use of scriptlets. It uses the prefix c.
75. List few JSTL core tags?
Following are JSTL core tags: