Re: Help with Java servlet : getServletContext().
- From: Ross Bamford <ross@xxxxxxxxxxxx>
- Date: Fri, 29 Apr 2005 18:17:54 +0100
On Fri, 2005-04-29 at 07:37 -0700, Vidya wrote:
> I am newbie to Java, am trying to get a program working, and I have
> imported the java packages below along with many other imports :
> import javax.servlet.GenericServlet;
> ....
> xsltFile = new File(getServletContext().getRealPath("xslt/" +
> template));
> if(!xsltFile.canRead()) {
> System.out.println("Error reading XSLT template file '"
> + xsltFile + "'.");
> return 0;
> }
>
> I get the following error, can anyone tell me what the problem is?
>
> com\netod\util\MyClass.java:243: cannot resolve symbol
> symbol : method getServletContext ()
> location: class com.netod.util.MyClass
> xsltFile = new File(getServletContext().getRealPath("xslt/"
> + template));
>
> thanks for any help
>
Without seeing more of your code, but as a "newbie to Java" I think it's
a fair guess you're after writing a Web servlet, rather than creating a
whole new type of servlet (such as FTP)?
If this is the case, instead of GenericServlet you should extend
javax.servlet.http.HttpServlet.
I'm not sure where the not found is coming from - perhaps you're
implementing straight Servlet (which doesn't have it) ? If changing to
HTTPServlet doesn't help, post more of your code.
Ross
--
[Ross A. Bamford] [ross AT the.website.domain]
Roscopeco Open Tech ++ Open Source + Java + Apache + CMF
http://www.roscopec0.f9.co.uk/ + info@xxxxxxxxxxxxxxxxxx
.
- Follow-Ups:
- References:
- Help with Java servlet : getServletContext().
- From: Vidya
- Help with Java servlet : getServletContext().
- Prev by Date: java assembler?? for Javap utility??
- Next by Date: Re: Help with Java servlet : getServletContext().
- Previous by thread: Re: Help with Java servlet : getServletContext().
- Next by thread: Re: Help with Java servlet : getServletContext().
- Index(es):
Relevant Pages
|