Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I compile mt Tag Handler...?

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to write a very simple tag. The tag handler is below:

package basic;

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

class Hello extends TagSupport {
public int doStartTag() throws JspException {
try {
pageContext.getOut().print("Hello World");
}
catch (Exception ex) {
throw new JspException("IO problems");
}

return SKIP_BODY;
}
}

At the command line, I type the relevant command to compile my code:

javac Hello.java

The errors I get are as follows:

Hello.java:3: package javax.servlet.jsp does not exist
import javax.servlet.jsp.*;
^
Hello.java:4: package javax.servlet.jsp.tagext does not exist
import javax.servlet.jsp.tagext.*;
^
Hello.java:6: cannot resolve symbol
symbol : class TagSupport
location: class basic.Hello
class Hello extends TagSupport {
^
Hello.java:7: cannot resolve symbol
symbol : class JspException
location: class basic.Hello
public int doStartTag() throws JspException {
^
Hello.java:9: cannot resolve symbol
symbol : variable pageContext
location: class basic.Hello
pageContext.getOut().print("Hello World");
^
Hello.java:12: cannot resolve symbol
symbol : class JspException
location: class basic.Hello
throw new JspException("IO problems");
^
Hello.java:15: cannot resolve symbol
symbol : variable SKIP_BODY
location: class basic.Hello
return SKIP_BODY;
^

Do I need to download a library before I can compile this code, or am I missing something else...?

Thanks!

Dan
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You will need the J2EE classes in your class path in order to compile a custom tag handler. You can get these by downloading the J2EE development kit from sun, and the jar file you need is named j2EE.jar. Also, your application server has these classes. For Tomcat, they're in common/lib, and there are several jar files you have to include in your classpath.
 
Dan Mortimer
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Merrill,

Thanks very much for your response. I took your advice and added the 4 .jar files in my <TOMCAT_HOME>/common/lib directory to my classpath and now my custom tag handler compiles.

Thanks again for your help!
 
It's never done THAT before. Explain it to me tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic