Search code examples
javajspjakarta-eejsp-tags

Simple JSP - Attribute invalid for tag according to TLD


My project in eclipse -

enter image description here

I get the error below when I run MyTagUser.jsp - HTTP Status 500 - /jsp/MyTagUser.jsp(14,0) Attribute subTitle invalid for tag Header according to TLD

org.apache.jasper.JasperException: /jsp/MyTagUser.jsp(14,0) Attribute subTitle 
invalid for tag Header according to TLD

org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
 org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)...etc.

Snippet from Header.jsp -

<body>
<img src="../images/java_logo.gif"><br>
<em><strong> ${subTitle} </strong></em> <br>
</body>

Snippet from MyTagUser.jsp -

<%@ taglib prefix="myTags" tagdir="/WEB-INF/tags"%>
<html>
<head>
</head>
<body>
<myTags:Header  subTitle="Java is the best !!!" />
JSP and Servlets.
</body>
</html>

Solution

  • You must use the attribute directive in your Header.tag file as show below -

    <body>
    <%@ attribute name="subTitle" required="true" rtexprvalue="true" %>
    <img src="../images/java_logo.gif"><br>
    <em><strong> ${subTitle} </strong></em> <br>
    </body>