Answer the question
In order to leave comments, you need to log in
Why does an Unable to find taglib error occur when calling custom tag?
Hello.
For the first time I decided to try out the custon taglib
java class
package RU.Tags.Examples;
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import java.io.*;
public class CustomAttribute extends SimpleTagSupport {
private String message;
public void setMessage(String msg) {
this.message = msg;
}
StringWriter sw = new StringWriter();
public void doTag()
throws JspException, IOException
{
if (message != null) {
/* Use message from attribute */
JspWriter out = getJspContext().getOut();
out.println("Первый кастом таг :"+ message );
}
else {
/* use message from the body */
getJspBody().invoke(sw);
getJspContext().getOut().println(sw.toString());
}
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>JSTL 1.1 core library</description>
<display-name>JSTL core</display-name>
<tlib-version>1.1</tlib-version>
<short-name>CustomAttribute</short-name>
<tag>
<name>Hello</name>
<tag-class>RU.Tags.Examples.CustomAttribute</tag-class>
<body-content>scriptless</body-content>
<attribute>
<name>message</name>
</attribute>
</tag>
</taglib>
<%@ taglib uri="/WEB-INF/jstl/custom_tag_attribute.tld" prefix="CustomAttribute" %>
<CustomAttribute:Hello message="This is custom tag" />
HTTP Status 500 - Unable to find taglib "CustomAttribute" for URI: /WEB-INF/jstl/custom_tag_attribute.tld
type Exception report
message Unable to find taglib "CustomAttribute" for URI: /WEB-INF/jstl/custom_tag_attribute.tld
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to find taglib "CustomAttribute" for URI: /WEB-INF/jstl/custom_tag_attribute.tld
Answer the question
In order to leave comments, you need to log in
completely forgot about web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<jsp-config>
<!-- JSTL Tag Library Local Descriptors -->
<taglib>
<taglib-uri>/WEB-INF/jstl/custom_tag_attribute.tld</taglib-uri>
<taglib-location>/WEB-INF/jstl/custom_tag_attribute.tld</taglib-location>
</taglib>
<taglib>
</web-app>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question