Re: Help with Java servlet : getServletContext().



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


.



Relevant Pages

  • Help with Java servlet : getServletContext().
    ... imported the java packages below along with many other imports: ... + template)); ...
    (comp.lang.java.help)
  • Re: ActiveDocument Not Getting Set on Document Open
    ... I'm not sure what you are attaching your templates to every document that's ... should consider using a global template, and make your menu changes to it. ... > I am having troubles with implementing a CommandBar in Microsoft Word ... > Imports Office.MsoControlType ...
    (microsoft.public.office.developer.com.add_ins)
  • Re: Help with Java servlet : getServletContext().
    ... >> 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: ... instance variables (where you have a local variable of the same name, ...
    (comp.lang.java.help)
  • asp.net page template *inheritance)
    ... reference and points to the statement PageBase.Render. ... I create the template by overriding the System.Web.UI.Page.Render method. ... Imports System.Web.UI ... ' Then we allow the base class to render the ...
    (microsoft.public.dotnet.framework.aspnet)
  • updating links in a macro
    ... I'm attempting to write a basic macro that imports from an excel file ... the template file changes. ...
    (microsoft.public.excel.misc)