JSP Custom Tags beginner questions...

I have just started learning about creating JSP Custom Tags, and I have a few questions:
(All questions refer to code below that I have been practicing with)

1. Who or which file calls the "setName" method?

2. Is setName a api method or could I also name it something like setTesting123?

3. Does the order of tags matter inside the tld file?

4. I am currently getting this error below with the provided files below, do you know why?
[Fri Oct 29 15:20:25 EDT 2004] The top-level uri tag is empty.
[Fri Oct 29 15:20:25 EDT 2004] JSP10Servlet: TLD attribute element must have a name element.
[Fri Oct 29 15:20:25 EDT 2004] JSP10Servlet: the problem occurred around line number 1:
[Fri Oct 29 15:20:25 EDT 2004] JSP10Servlet: [<%@ taglib uri="myTags" prefix="first" %>]


5. I am using Servlet Exec as my Application Server.
******* Code Below ********
Thank you for all your help !
G.

**** 2 jsp files, Hello and HelloTagParam.jsp *********

Hello.jsp

<%@ taglib uri="myTags" prefix="first"%>
<HTML>
<HEAD>
<TITLE>First Tag</TITLE>
</HEAD>

<BODY>

<B>My FFirst tag prints this </B>:

<first:hello/>

</BODY>
</HTML>


HelloTagParam.jsp
<%@ taglib uri="myTags" prefix="first" %>
<HTML>
<HEAD>
<TITLE>Hello Tag with Parameter</TITLE>
</HEAD>

<BODY>
<B>My parameterized tag prints</B>:

<P>

<first:helloparam name="JavaDuke"/>

</BODY>
</HTML>

************ TLD ***********************
<?xml version="1.0" encoding="ISO-8859-1" ?>

<!-- a tag library descriptor -->

<taglib>
   <tlibversion>1.0</tlibversion>
   <jspversion>1.1</jspversion>
   <shortname>first</shortname>
   <uri></uri>
   <info>A simple tab library for the examples</info>

  <tag>
    <name>hello</name>
    <tagclass>tags.HelloTag</tagclass>
    <bodycontent>empty</bodycontent>
    <info>Say Hi</info>
  </tag>  
 
  <tag>
    <name>helloparam</name>
    <tagclass>tags.HelloTagParam</tagclass>
    <bodycontent>empty</bodycontent>
    <info>Tag with Parameter</info>
    <attribute>
      <testing>testing</testing>
      <required>false</required>
      <rtexprvalue>false</rtexprvalue>
    </attribute>
  </tag>

</taglib>

****** Java classes: HelloTag.java and HelloTagParam.java ******

//HelloTag.java
package tags;

import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class HelloTag extends TagSupport {

   public int doStartTag() throws JspException {
      try {
         pageContext.getOut().print("This is my first tag!");
      } catch (IOException ioe) {
         throw new JspException("Error:IOException while writing to client" + ioe.getMessage());
      }
      return SKIP_BODY;
   }

   public int doEndTag() throws JspException {
      return SKIP_PAGE;
   }
}


//HelloTagParam.java
package tags;

import java.io.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class HelloTagParam extends TagSupport {
   private String name;

   
   public void setName(String name) {
      this.name = name;
   }
   

   public int doStartTag() throws JspException {
      try {
         pageContext.getOut().print("*** *** Welcome to JSP Tag Programming, " +name);
      } catch (IOException ioe) {
         throw new JspException("Error:IOException while writing to client");
      }
      return SKIP_BODY;
   }

   public int doEndTag() throws JspException {
      return SKIP_PAGE;
   }
}



gen228Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MogalManicCommented:
I think the URI needs to be specified in the taglib.
0
siliconeagleCommented:
you need to define that taglib at the end of your web.xml
 <taglib>
  <taglib-uri>/WEB-INF/myTags</taglib-uri>
  <taglib-location>/WEB-INF/myTags.tld</taglib-location>
 </taglib>

in this case you tag library descriptor (tld) file is called myTags.tld as is located in your WWEB-INF directory. to use your tag lib in a JSP use :-
<%@ taglib uri="/WEB-INF/myTags" prefix="first" %>
...
<first:hello/>
...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gen228Author Commented:
Thank you for your comments MogalManic and siliconeagle !  I found out that my problem had to do with the actual tld file itself, I created a new tld file and somehow it worked.  Can someone answer these questions:

1. Who or which file calls the "setName" method?

2. Is setName a api method or could I also name it something like setTesting123?

3. Does the order of tags matter inside the tld file?

Thank you so much !
G.
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

gen228Author Commented:
Thanks again for your comments and answers !

G.
0
siliconeagleCommented:
1. its called from the java class that is generated from the JSP the actual file will be in the work directory of the server.

2. setName is declared in you Tag Class "HelloTagParam.java" it is intended that you use these metohds to get the data input for the name parameter of your tag.

3. No
0
gen228Author Commented:
Thank you siliconeagle, I found out that it sets it based upon the tag attribute name that I create.

Thanks again,
G.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.