relative file path

Discussion in 'Java' started by Asad, May 26, 2004.

  1. Asad

    Asad Guest

    I have a JSP located at:

    G:/tomcat4/webapps/reportmanager/foo.jsp

    Inside this jsp file I have this scriptlet:

    <%
    File Name= new File("G:/tomcat4/webapps/reportmanager/WEB-INF/classes/sample.xml");
    if(!Name.exists())
    {
    %> sample.xml does not exist <%
    }
    else
    {
    %> sample.xml exists! <%
    }
    %>

    Now I want to use relative filepath, but I am unable to do that. I
    tried the following instead of the path indicated above but none of
    these seem to work:

    /WEB-INF/classes/sample.xml
    ../WEB-INF/classes/sample.xml
    WEB-INF/classes/sample.xml

    Note, once again that foo.jsp is located at
    G:/tomcat4/webapps/reportmanager/foo.jsp itself.

    Any ideas?

    Thanks.
     
    Asad, May 26, 2004
    #1
    1. Advertising

  2. Andrew Thompson, May 26, 2004
    #2
    1. Advertising

  3. Try
    servletContext.getRealPath("sample.xml");

    HTH,
    - Manish

    "Asad" <> wrote in message
    news:...
    > I have a JSP located at:
    >
    > G:/tomcat4/webapps/reportmanager/foo.jsp
    >
    > Inside this jsp file I have this scriptlet:
    >
    > <%
    > File Name= new

    File("G:/tomcat4/webapps/reportmanager/WEB-INF/classes/sample.xml");
    > if(!Name.exists())
    > {
    > %> sample.xml does not exist <%
    > }
    > else
    > {
    > %> sample.xml exists! <%
    > }
    > %>
    >
    > Now I want to use relative filepath, but I am unable to do that. I
    > tried the following instead of the path indicated above but none of
    > these seem to work:
    >
    > /WEB-INF/classes/sample.xml
    > ./WEB-INF/classes/sample.xml
    > WEB-INF/classes/sample.xml
    >
    > Note, once again that foo.jsp is located at
    > G:/tomcat4/webapps/reportmanager/foo.jsp itself.
    >
    > Any ideas?
    >
    > Thanks.
    >
     
    Manish Hatwalne, May 26, 2004
    #3
  4. Asad

    Asad Guest

    Try that where? Inside my jsp? I don't believe this has anything to do
    with my problem; which was that I did not want to place sample.xml in
    the same folder as my JSP. And if I placed my xml file in some other
    folder, then the relative path to that location wasn't working.

    So what are you suggesting!?



    "Manish Hatwalne" <> wrote in message news:<>...
    > Try
    > servletContext.getRealPath("sample.xml");
    >
    > HTH,
    > - Manish
    >
    > "Asad" <> wrote in message
    > news:...
    > > I have a JSP located at:
    > >
    > > G:/tomcat4/webapps/reportmanager/foo.jsp
    > >
    > > Inside this jsp file I have this scriptlet:
    > >
    > > <%
    > > File Name= new

    > File("G:/tomcat4/webapps/reportmanager/WEB-INF/classes/sample.xml");
    > > if(!Name.exists())
    > > {
    > > %> sample.xml does not exist <%
    > > }
    > > else
    > > {
    > > %> sample.xml exists! <%
    > > }
    > > %>
    > >
    > > Now I want to use relative filepath, but I am unable to do that. I
    > > tried the following instead of the path indicated above but none of
    > > these seem to work:
    > >
    > > /WEB-INF/classes/sample.xml
    > > ./WEB-INF/classes/sample.xml
    > > WEB-INF/classes/sample.xml
    > >
    > > Note, once again that foo.jsp is located at
    > > G:/tomcat4/webapps/reportmanager/foo.jsp itself.
    > >
    > > Any ideas?
    > >
    > > Thanks.
    > >
     
    Asad, May 27, 2004
    #4
  5. Asad

    Asad Guest

    You have given me a link back to my own posting!



    Andrew Thompson <> wrote in message news:<>...
    > On 26 May 2004 02:45:31 -0700, Asad wrote:
    >
    > > I have a JSP located at:

    >
    > <http://google.com/groups?th=e958208ee05589#link3>
    >
    > HTH
     
    Asad, May 27, 2004
    #5
  6. > "Manish Hatwalne" wrote in message news:...

    >> Try servletContext.getRealPath("sample.xml");


    Given the directory structure, this may work better..

    servletContext.getRealPath("/WEB-INF/classes/sample.xml);

    HTH

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, May 27, 2004
    #6
  7. On 26 May 2004 21:38:24 -0700, Asad wrote:

    > You have given me a link back to my own posting!


    (chuckles) How silly of me.. It was *supposed*
    to be a link, to a post that answered the question
    - see my other post.

    And please do not top-post..
    <http://www.physci.org/codes/javafaq.jsp#netiquette>

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, May 27, 2004
    #7
  8. Asad

    Asad Guest

    Andrew Thompson <> wrote in message news:<97tfydq7y1sz$.1wgi88xgdxihz$>...
    > On 26 May 2004 21:38:24 -0700, Asad wrote:
    >
    > > You have given me a link back to my own posting!

    >
    > (chuckles) How silly of me.. It was *supposed*
    > to be a link, to a post that answered the question
    > - see my other post.
    >
    > And please do not top-post..
    > <http://www.physci.org/codes/javafaq.jsp#netiquette>


    And you still didn't give me the link that supposedly solved my
    problem! But that's ok. I figured it out by printing absolulte and
    relative paths. My servlet was running inside the bin directory and so
    I had to move back one step to the parent and then give the path.

    HTH anyone else who's going through the same problem.

    Asad
     
    Asad, May 28, 2004
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    3
    Views:
    19,723
    Sudsy
    Jul 8, 2004
  2. Nomak
    Replies:
    4
    Views:
    1,273
    Nomak
    Jul 18, 2005
  3. Thomas Guettler
    Replies:
    3
    Views:
    792
    Andrei
    Oct 27, 2003
  4. Oren
    Replies:
    1
    Views:
    574
    Michael D. Ober
    Apr 29, 2007
  5. Nigel Wilkinson
    Replies:
    2
    Views:
    420
    Nigel Wilkinson
    Jul 25, 2005
Loading...

Share This Page