In TLD file: Add short-name and change uri from customTag to /customTag
<short-name>operator</short-name>
<uri>/customTag</uri>
In JSP
<@ taglib prefix="operator" uri="/customTag" />
Question
When i try map custom tag, i am getting Error: 500
with a message File "/customTag" not found
Here is my attempt: myTag.tld
<taglib version="2.0" xmlns="http://java.sun.com/xml/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
>
<uri>customTag</uri>
<tlib-version>1.0</tlib-version>
<tag>
<name>multiplier</name>
<tag-class>myPack.MultiplierTag</tag-class>
<attribute>
<name>input</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
jsp page
<%@taglib uri="/customTag" prefix="operator"%>
<%
String input = request.getParameter("input");
%>
<operator:multiplier input="<%=input%>"></operator:multiplier>
When i am trying to access .tld
file using file name then everything is fine
Solution
In TLD file: Add short-name and change uri from customTag to /customTag
<short-name>operator</short-name>
<uri>/customTag</uri>
In JSP
<@ taglib prefix="operator" uri="/customTag" />
OTHER TIPS
I am not JEE expert but I just created my own tld
based on your example and example from Head First: Servlets and JSP and it seems that:
uri
you need to specify name that you will use in <%@taglib uri="..."
so if it is <uri>customTag</uri>
then you need to use it as <%@taglib uri="customTag"
body-content
, which for your example can be set to empty
So try with this tld which you can place in /WEB-INF/tlds/myTag.tld
<taglib version="2.0" xmlns="http://java.sun.com/xml/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd">
<uri>customTag</uri>
<tlib-version>1.0</tlib-version>
<tag>
<name>multiplier</name>
<tag-class>myPack.MultiplierTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>input</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
For implementation you can use
package myPack;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
public class MultiplierTag extends SimpleTagSupport {
private String input;
public void doTag() throws JspException, IOException {
getJspContext().getOut().write("Hello " + input + " <br>");
}
public void setInput(String input) {
this.input = input;
}
}
and for demonstration you can use your earlier JSP
<%@taglib uri="customTag" prefix="operator"%>
<%
String input = "World";//request.getParameter("input");
%>
<operator:multiplier input="<%=input%>"></operator:multiplier>
Don't forget to republish your project after updating it.