[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

JSP Custom Tags beginner questions...

Posted on 2004-10-29
6
Medium Priority
?
251 Views
Last Modified: 2013-11-24
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;
   }
}



0
Comment
Question by:gen228
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 21

Assisted Solution

by:MogalManic
MogalManic earned 160 total points
ID: 12456507
I think the URI needs to be specified in the taglib.
0
 
LVL 2

Accepted Solution

by:
siliconeagle earned 240 total points
ID: 12461623
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
 

Author Comment

by:gen228
ID: 12464035
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:gen228
ID: 12478398
Thanks again for your comments and answers !

G.
0
 
LVL 2

Expert Comment

by:siliconeagle
ID: 12481466
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
 

Author Comment

by:gen228
ID: 12486522
Thank you siliconeagle, I found out that it sets it based upon the tag attribute name that I create.

Thanks again,
G.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question