URGENT! Please help! Access files through absolute path

Discussion in 'Java' started by javadev, Nov 5, 2006.

  1. javadev

    javadev Guest

    Hello

    I have a java based web application deployed on Apache Tomcat.

    On one of my JSP pages, I try to display an image, the path of which is
    an absolute path (say, C:\somePic.jpg) pointing to a location on the
    server on which the application is deployed. However when I try to
    access this web page from a different machine, it looks for this image
    file on the local machine and not the server. How can I specify an
    absolute path but still make sure that the jsp page is picking up the
    image from the server and not the local machine on which it is being
    run?

    Thanks
    Swetha
     
    javadev, Nov 5, 2006
    #1
    1. Advertising

  2. javadev wrote:
    ....
    > I have a java based web application deployed on Apache Tomcat.
    >
    > On one of my JSP pages, I try to display an image, the path of which is
    > an absolute path (say, C:\somePic.jpg) pointing to a location on the
    > server on which the application is deployed. However when I try to
    > access this web page from a different machine, it looks for this image
    > file on the local machine and not the server. How can I specify an
    > absolute path but still make sure that the jsp page is picking up the
    > image from the server and not the local machine on which it is being
    > run?


    Uh-huh.. well, to fix that, simply... wait (checks sub.)

    Sub: URGENT! ....

    Oh.. (checks watch) apparently I'm too late.
    Never mind.























    ;-)

    [ Look into ServletContext.getRealPath() ]

    Andrew T.
     
    Andrew Thompson, Nov 5, 2006
    #2
    1. Advertising

  3. javadev

    javadev Guest

    Thanks Andrew

    How can I get a handle to the servletcontext object?

    Swetha

    Andrew Thompson wrote:
    > javadev wrote:
    > ...
    > > I have a java based web application deployed on Apache Tomcat.
    > >
    > > On one of my JSP pages, I try to display an image, the path of which is
    > > an absolute path (say, C:\somePic.jpg) pointing to a location on the
    > > server on which the application is deployed. However when I try to
    > > access this web page from a different machine, it looks for this image
    > > file on the local machine and not the server. How can I specify an
    > > absolute path but still make sure that the jsp page is picking up the
    > > image from the server and not the local machine on which it is being
    > > run?

    >
    > Uh-huh.. well, to fix that, simply... wait (checks sub.)
    >
    > Sub: URGENT! ....
    >
    > Oh.. (checks watch) apparently I'm too late.
    > Never mind.
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > ;-)
    >
    > [ Look into ServletContext.getRealPath() ]
    >
    > Andrew T.
     
    javadev, Nov 5, 2006
    #3
  4. javadev

    javadev Guest

    I figured I can use application.getRealPath coz application is of type
    ServletContext.

    Thanks
    Swetha


    Andrew Thompson wrote:
    > javadev wrote:
    > ...
    > > I have a java based web application deployed on Apache Tomcat.
    > >
    > > On one of my JSP pages, I try to display an image, the path of which is
    > > an absolute path (say, C:\somePic.jpg) pointing to a location on the
    > > server on which the application is deployed. However when I try to
    > > access this web page from a different machine, it looks for this image
    > > file on the local machine and not the server. How can I specify an
    > > absolute path but still make sure that the jsp page is picking up the
    > > image from the server and not the local machine on which it is being
    > > run?

    >
    > Uh-huh.. well, to fix that, simply... wait (checks sub.)
    >
    > Sub: URGENT! ....
    >
    > Oh.. (checks watch) apparently I'm too late.
    > Never mind.
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > ;-)
    >
    > [ Look into ServletContext.getRealPath() ]
    >
    > Andrew T.
     
    javadev, Nov 5, 2006
    #4
  5. javadev

    javadev Guest

    Ok, what happens now when I use application.getRealPath(absPath) where
    absPath is a string that contains the absolute path of the file (say,
    C:\somePic.jsp) is that the absolute path just gets appended to the
    path of the application on the server so it ends up as "C:\Program
    Files\Tomcat\webapps\myApp\C:\somePic.jpg which still does not work.
    Any ideas on what I can do to fix this?


    Andrew Thompson wrote:
    > javadev wrote:
    > ...
    > > I have a java based web application deployed on Apache Tomcat.
    > >
    > > On one of my JSP pages, I try to display an image, the path of which is
    > > an absolute path (say, C:\somePic.jpg) pointing to a location on the
    > > server on which the application is deployed. However when I try to
    > > access this web page from a different machine, it looks for this image
    > > file on the local machine and not the server. How can I specify an
    > > absolute path but still make sure that the jsp page is picking up the
    > > image from the server and not the local machine on which it is being
    > > run?

    >
    > Uh-huh.. well, to fix that, simply... wait (checks sub.)
    >
    > Sub: URGENT! ....
    >
    > Oh.. (checks watch) apparently I'm too late.
    > Never mind.
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    > ;-)
    >
    > [ Look into ServletContext.getRealPath() ]
    >
    > Andrew T.
     
    javadev, Nov 5, 2006
    #5
  6. javadev

    Daniel Pitts Guest

    javadev wrote:
    > Ok, what happens now when I use application.getRealPath(absPath) where
    > absPath is a string that contains the absolute path of the file (say,
    > C:\somePic.jsp) is that the absolute path just gets appended to the
    > path of the application on the server so it ends up as "C:\Program
    > Files\Tomcat\webapps\myApp\C:\somePic.jpg which still does not work.
    > Any ideas on what I can do to fix this?


    Please don't top post, thanks.

    Generally its a bad idea to serve files outside of some predefined
    docroot. If you server C:\somePic.jpg, what is to prevent someone from
    retrieving anything else on your hard drive? Its best to move the jpg
    files into some resource directory under your webapp root.

    Good luck,
    Daniel.
     
    Daniel Pitts, Nov 5, 2006
    #6
    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,671
    Sudsy
    Jul 8, 2004
  2. Replies:
    10
    Views:
    3,769
  3. Thomas Guettler
    Replies:
    3
    Views:
    782
    Andrei
    Oct 27, 2003
  4. Nigel Wilkinson
    Replies:
    2
    Views:
    411
    Nigel Wilkinson
    Jul 25, 2005
  5. James Byrne
    Replies:
    3
    Views:
    600
    James Byrne
    Sep 14, 2010
Loading...

Share This Page