You are reading the article Top 3 Examples To Implement Of Jsp Tag Libraries updated in October 2023 on the website Benhvienthammyvienaau.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested November 2023 Top 3 Examples To Implement Of Jsp Tag Libraries
Introduction to JSP TaglibJsp(java server pages) is one of the dynamic programming languages to develop creative web pages based on Html, Xml, and some web services like Rest and Soap. The jsp have their own standard tag libraries its nothing but one of the component for java enterprise edition web applications platform. The JSP Taglib will use the jsp codes like jsp tags for use in the library specifications for some processes like xml data processing, internationalization concepts, etc. Jsp allows the vendors for creating their own custom jsp tag libraries a tag library defined as a collection of user defined actions tags will be created by the developers.
Start Your Free Software Development Course
Syntax:
The basic syntax of the jsp using the tag libraries as follows.
The above codes are the jsp codes use it for the custom libraries in the jsp tags.
How to Use JSP Taglib?The user-defined tags actions can be created one or more server-side instances is used for the tag libraries or using with the other jsp script elements like scriptlets also known as scripting variables. The scripting variables details and the variable instances are specified in the class called tag-extra-info class is also used to defined the custom tag usages. The tag handler concept will be used for the nested tag elements parent-child relationship mentioned in the concept for nested tags but it specified in the inner side only applicable for the programming scripts in jsp the tag handler handles the nested tag for outer side tags.
The tag handler have its own instances for java class that will be implemented for one of two important standard java interfaces it depends between the start and end side of the tags. For each and every jsp tags have their own handle classes. The tag handler instances of the server-side objects used at the specified request time period and also it has their own properties that have to be set by the jsp containers it also includes the page context instances for each jsp page that will be used in the custom tags the parent tag handler instances it will be used in the custom tag instances is nested with the outer side of the custom tag.
The custom tags will be used for some time may have body tag and sometimes its not . And also the custom tag may have the body tag it also not handle in the tags is nothing but the special handlers. It is possible for three different situations like there is no body tag that time opposed for the only start and end tag in some cases there is the body that does not need for the special handling by the tag handlers and final case is the body that needs special handling with the tag handlers.
Examples to Implement of JSP TaglibBelow are the examples of jsp tag libraries:
Example #1Code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" package com.first; import java.util.Calendar; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; public class tagHandler extends TagSupport{ public int doStartTag() throws JspException { JspWriter j=pageContext.getOut(); try{ j.print(Calendar.getInstance().getTime()); }catch(Exception e){System.out.println(e);} return SKIP_BODY; } } <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"Output:
Example #2Code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" Today Date and Time is: public class tagHandler extends SimpleTagSupport{ private String numformat; private String num1; public tagHandler() { } public void setnumFormat(String numformat) { this.numformat = numformat; } public void setNum1(String num1) { this.num1 = num1; } public void doTag() throws JspException, IOException { System.out.println("Given Number is:" + num1); System.out.println("Number Format is:" + numformat); try { double d = Double.parseDouble(num1); DecimalFormat f = new DecimalFormat(numformat); String s = f.format(d); getJspContext().getOut().write(s); } catch (Exception e) { e.printStackTrace(); throw new SkipPageException("Exception in formatting " + num1 + " with format " + numformat); } } } Example #3Code:
public class tagHandler extends SimpleTagSupport{ private String frommsg; private String tomsg; public void setFrommsg( final String frommsg ) { this.frommsg = frommsg; } public void setTomsg( final String tomsg ) { this.tomsg = tomsg; } public void doTag() throws JspException, IOException { final StringWriter s = new StringWriter(); getJspBody().invoke( s ); getJspContext().getOut().println( "Welcome Messages'" + frommsg + "' tomsg '" + tomsg + "'. To My Domain '" + s.toString() + "'" ); } }
Output:
ConclusionJsp custom tags and predefined tags are used as per the customer requirement also the tld file contains a single tag library with one or more tag definitions. In Jsp 2.0 version have the feature called simple tag support class these class implemented the SimpleTag interfaces and we used getter methods to retrieve the properties.
Recommended ArticleThis is a guide to JSP Taglib. Here we discuss the Introduction to JSP Taglib and how to use it along with its examples and Code Implementation. You can also go through our other suggested articles to learn more –
You're reading Top 3 Examples To Implement Of Jsp Tag Libraries
Update the detailed information about Top 3 Examples To Implement Of Jsp Tag Libraries on the Benhvienthammyvienaau.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!