We can use the custom URI, to tell the web container about the tld file. In such case, we need to define the taglib element in the web.xml. The web container gets the information about the tld file from the web.xml file for the specified URI.
Example to use custom URI in JSP Custom Tag
In this example, we are going to use the custom uri in the JSP file. For this application, we need to focus on 4 files.
- index.jsp
- web.xml
- mytags.tld
- PrintDate.java
index.jsp
<%@ taglib uri="mytags" prefix="m" %> Today is:
web.xml
mytags /WEB-INF/mytags.tld
mytags.tld
1.0 1.2 simple mytags A simple tab library for the examples today com.javatpoint.taghandler.PrintDate
PrintDate.java
package com.javatpoint.taghandler; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; public class PrintDate extends TagSupport{ public int doStartTag() throws JspException { JspWriter out=pageContext.getOut(); try{ out.print(java.util.Calendar.getInstance().getTime()); }catch(Exception e){e.printStackTrace();} return SKIP_BODY; } }
Leave A Comment