You can only go back to the root of your project when using getResource

For the servlet 2.3 specs:

        "The getResource and getResourceAsStream methods take a String with
a
        leading "/" as argument which gives the path of the resource
relative to the root of
        the context. This hierarchy of documents may exist in the server's
file system, in a
        web application archive file, on a remote server, or at some other
location."

As you can see beginning with the / is a requirement.

for mine, i use getServletContext().getResource("/flow.xml");
This refers to the /flow.xml in my root directory.
If your Register1.asp is not in the root directory or its subfolders then
you need to move it.
-Tim

-----Original Message-----
From: Varley, Roger [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 20, 2002 8:15 AM
To: [EMAIL PROTECTED]
Subject: Re: Your Message Sent on Tue, 19 Mar 2002 15:35:33 -0000


>
>  You should use something like
>
>         ServletContext ct = config.getServletContext();
>
>         URL url=ct.getResource("/WEB-INF/foo/bar/bletch")
>
> This avoid hard coding in a path in to your servlet, which
> avoids all sorts of
> .. problems.
>

Thanks for your response but this doesn't work. If I try

        ServletContext sc = config.getServletContext();
        URL url = sc.getResource("../../ipscgibin/Register1.asp");
      URLConnection uc = url.openConnection();

then the servlet crashes with a null pointer exception and Tomcat outputs
the message
"Unsafe Path e:\tomcat\webapps\Application /../../iscgibin/Register1.asp" So
it would appear that using a relative path with getResource() doesn't step
up the web site hierachy. I can get around the problem with creating a new
URL object using an absoloute path, but this means I have to mainain two
versions of the servlet, one for our test site and one for production which
doesnt seem a very good way and maintaining a properties file seems a bit of
an overkill. Surely there must be a simple way of specifying a relative path
that steps out of the Tomcat/servlet structure onto the wwwroot hierachy.

Regards
Roger

> >
> >Hi
> >
> >I'm using Tomcat 3.2 and IIS on Windows NT. I have a servlet that is
> >accessed by the url wwwroot/Application/servlet/ServletName and is
> >physically located at
> e:\tomcat\Application\WEB-INF\classes\ServletName.
> >Within the servlet I want to open a URLConnection and I want
> to build the
> >URL object specifying a relative path to
> wwwroot/cgibin/program_name. I
> >can't work out how the Tomcat path fits into the web
> hierachy so I get the
> >right number of "/../../'s" into my path. How do I specify the path?
> >
> >url = new URL("../../cgibin/programe_name") doesn't appear to work.
> >
> >Regards
> >Roger
> >

************************************************************************
Information in this message is confidential and may be privileged.  It is
for the exclusive use of the intended recipient(s).  If you are not the
intended recipient(s) please notify the sender and delete the message
immediately.  Unauthorised disclosure, distribution and copying of this
email is strictly prohibited.  The opinions expressed within this message
are those of the individual author.  Whilst Brake Bros takes reasonable
steps to scan this email it does not accept liability for any virus that may
be contained in it.
Bros Foodservice Limited, Enterprise House, Eureka Business Park, Ashford,
Kent TN25 4AG.
Registered in England and Wales number 706764.
Telephone 01233 206000 Fax 01233 206006.

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to