wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes attribute problem in custom tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "attribute problem in custom tag" Watch "attribute problem in custom tag" New topic

attribute problem in custom tag

Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

Hello everybody......
I had tried to run the following programme of custom tag from HFSJ but it throws Exception as: "org.apache.jasper.JasperException: /result.jsp(7,0) According to the TLD or the tag file, attribute user> is mandatory for tag "

my source code in the programme and directory structure as:

1)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\form.html

2)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\result.jsp

3)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\WEB-INF\tlds\test.tld

4)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\WEB-INF\lib\jstl.jar

5)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\WEB-INF\lib\standard.jar

6)C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\readTld\WEB-INF\classes\foo\AdviserTagHandler.class

And the source code as follows
1) form.html

<form action = "result.jsp" method="Get">
<h1> Login Page </h1>
Name:<input type="text"name="userName">
Password:<input type="password"name="userPassword">
<input type = "SUBMIT">

2) result.jsp


<%@ taglib prefix="mine" uri="randomThings" %>
Adviser Page

<mine:advice user ="${param.userName}" />


<?xml version="1.0" encoding="ISO-8859-1" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0">
<description>random advice</description>




4) and 5) are jar files

6) java file of AdviserTagHandler.class is like as:

package foo;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;

public class AdviserTagHandler extends SimpleTagSupport
private String user;

public void doTag() throws JspException,IOException
getJspContext().getOut().write("Your advice is:"+getAdvice());

public void setUser(String user)
this.user = user;

String getAdvice()
String[] adviceString = {"That color's is not working for you","You should call in sick.","You might have to rethink that haircut."};
int random = (int)(Math.random()*adviceString.length);
return adviceString[random];

so, Please tell me what's wrong in this programme as it says:According to the TLD or the tag file, attribute user> is mandatory for tag

Life is easy because we write the source code.....
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Pramod. There is an error present in test.tld. Use
Pramod P Deore
Ranch Hand

Joined: Jul 15, 2008
Posts: 629

yes I think you are right.
Thank you Chinmaya

will you please tell me how the control is transfer from form.html to result.jsp and tag handler.
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
Hi Pramod. When we submit the form, the control goes to the result.jsp. In result.jsp, there is taglib directive, the container sees the uri and locates the corresponding tld file by searching the predifined locations and it calls the appropriate tag handler class. At this time tag handler life cycle starts, and atlast control will return to the result.jsp and the response will sent to the client.
jQuery in Action, 2nd edition
subject: attribute problem in custom tag
Similar Threads
org.apache.jasper.JasperException: Unable to compile class for JSP:
HTTP Status 404 - /myApp/servlet/Testing
Request Resource not available.
Compiling java file
Compiling my first custom tag handler