Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Tags - Help!  RSS feed

 
Sathya Samy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying a small JSP tag library example over application.
When I try to create a class file using the following program I am getting errors saying that the TagSupport,JSPException are unresolved symbols :

package com.tek271.testTags;

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

public class TagList extends BodyTagSupport {

private List mItems;

public void setItems(List aItems) {
mItems = aItems;
}

public int doAfterBody() throws JspException {
BodyContent body = getBodyContent();
String text = body.getString().trim();
List list = text.length() >0 ? text2List(text) : mItems;
if (list == null) return SKIP_BODY;

try {
JspWriter out = body.getEnclosingWriter();
out.println("<select>");
String item;
for (int i=0; i<list.size(); i++) {
item = (String)list.get(i);
if (item.length()==0) continue;
out.println(" <option>" + item + "</option>");
}
out.println("</select>");
} catch (IOException ex) {
throw new JspTagException(ex.getMessage());
} // try

return SKIP_BODY;
} // doAfterBody()

/** Break aText into a list of lines */
private List text2List(String aText) {
List list = new ArrayList();
StringTokenizer tz = new StringTokenizer(aText, "\n\r");
String item;
while (tz.hasMoreTokens()) {
item = tz.nextToken().trim();
if (item.length() > 0) list.add(item);
} // while
return list;
} // text2List()

} // TagList


The question is where should I put this program for compilation to create a class file.I am using Apache Tomact 1.4 ?

Thanks in advance for your answers!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"java devil" -

Welcome to the JavaRanch! Please adjust your displayed name to meet the
JavaRanch Naming Policy. User names cannot be obviously fake.

You can change your user name here.

You need to add the JAR files containing JSP/Servlet/etc. classes to your classpath. Either download the J2EE API from Sun and add the j2ee.jar to your classpath, or look in the $CATALINA_HOME/common/lib directory for jsp-api.jar and servlet-api.jar and add those to your classpath. ($CATALINA_HOME is the directory that Tomcat was installed to.)

Thanks! and welcome to the JavaRanch!
 
Sathya Samy
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have copied servlet.jar (as I found that alone in common\lib directory)to my classpath.

But it does not work as it gives the same error messages.

Thanks in advance!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sathyasamy " -

Sorry but your name still doesn't meet the
JavaRanch Naming Policy. Your name must have a first and last name separated by a space.

You can change your user name here.

Then you will need to look for the JAR file containing the JSP API in the common/lib directory also... if you want to make sure the JAR contains the needed files for tags, you can open it in WinZip (or any other Zip program you want to use) and look for Tag related classes.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!