I want to use something like this in my jsp document files:
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
However, in all the 30+ examples I've seen, everyone uses simple jsp syntax, not jsp document syntax. Something like this:
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
xmlns:t="/WEB-INF/tags"
xmlns="http://www.w3.org/1999/xhtml"
version="2.0">
simply does not work. All the tag files which reside in /WEB-INF/tags aren't seen on the page. Only if I define a tld file, and list all the tags there, they can be accessed on the page. Is it possible to avoid tld declaration and still use tag files in a jsp document page?
1 Create tags directory in your WEB-INF/ directory
2 Create sample.tag file where your tag will be:
<%@ attribute name="exampleAttribute" required="true" type="java.lang.String" description="Example attribute" %>
<c:out value="${exampleAttribute}">
3 Declare tag library at you jsp where you want to use it:
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
4 Use it:
<tags:sample exampleAttribute="Hello from custom tag!"/>
And I think you should have version of web application 2.5. Think only from that version JSP 2.0 is supported (check in web.xml).
You need to put the prefix "urn:jsptagdir:" in your xmlns attribute. In your case,
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
xmlns:t="urn:jsptagdir:/WEB-INF/tags"
xmlns="http://www.w3.org/1999/xhtml"
version="2.0">
You can also use the prefix "urn:jsptld:" to specify the location of a TLD. For more details, see the section on "Declaring Tag Libraries" in http://docs.oracle.com/javaee/1.4/tutorial/doc/JSPX3.html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With