getting the disk absolute path of a web-app

Discussion in 'Java' started by yair, Nov 4, 2004.

  1. yair

    yair Guest

    hey all
    in a servlet running in tomcat, how can i get the full path of my web
    application on the disk (something like "c:\progran
    files\tomcat\webapps\myApp")?
    i don't want to write it in the web.xml or to pass it as a system
    property.
    thanks
    yair
     
    yair, Nov 4, 2004
    #1
    1. Advertising

  2. Andrew Thompson, Nov 4, 2004
    #2
    1. Advertising

  3. yair

    Will Hartung Guest

    "Andrew Thompson" <> wrote in message
    news:1r726yuynwivh$...
    > On 4 Nov 2004 02:35:57 -0800, yair wrote:
    >
    > > how can i get the full path of my web
    > > application on the disk (something like "c:\progran
    > > files\tomcat\webapps\myApp")?

    >
    > javax.servlet.ServletContext.getRealPath(java.lang.String)


    However, this is not guaranteed to not return null. If, for example, your
    web-app is running from an unexploded WAR file, you won't get a useable
    value.

    Regards,

    Will Hartung
    ()
     
    Will Hartung, Nov 4, 2004
    #3
  4. yair

    Juha Laiho Guest

    (yair) said:
    >in a servlet running in tomcat, how can i get the full path of my web
    >application on the disk (something like "c:\progran
    >files\tomcat\webapps\myApp")?
    >i don't want to write it in the web.xml or to pass it as a system
    >property.


    Adding to the response by Will Hartung; for what would you need this;
    what would you do with the information? Once we know that, we may be
    able to propose alternative ways of solving the problem.
    --
    Wolf a.k.a. Juha Laiho Espoo, Finland
    (GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
    PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
    "...cancel my subscription to the resurrection!" (Jim Morrison)
     
    Juha Laiho, Nov 6, 2004
    #4
  5. yair

    yair Guest

    Juha Laiho <> wrote in message news:<cmjbqi$2r2$-int>...
    > (yair) said:
    > >in a servlet running in tomcat, how can i get the full path of my web
    > >application on the disk (something like "c:\progran
    > >files\tomcat\webapps\myApp")?
    > >i don't want to write it in the web.xml or to pass it as a system
    > >property.

    >
    > Adding to the response by Will Hartung; for what would you need this;
    > what would you do with the information? Once we know that, we may be
    > able to propose alternative ways of solving the problem.


    thanks for u're answer first.

    i will have a folder named "tests" under webapps/myApp, and i want to
    read the names of the files in this folder. i m going to show the user
    a page with the names of those files and let him choose a file to run
    (this ofcourse is a very simplified version of what i m trying to do).
    this webapp will not be JAR-ed, so i dont have a problem with that.

    it seems like:
    javax.servlet.ServletContext.getRealPath("")
    or
    javax.servlet.ServletContext.getRealPath("/")
    r working fine, i think i'll use this way.
    thanks
    yair
     
    yair, Nov 7, 2004
    #5
    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. Jas Shultz
    Replies:
    0
    Views:
    993
    Jas Shultz
    Dec 3, 2003
  2. Matt
    Replies:
    3
    Views:
    19,720
    Sudsy
    Jul 8, 2004
  3. Replies:
    10
    Views:
    3,827
  4. Thomas Guettler
    Replies:
    3
    Views:
    791
    Andrei
    Oct 27, 2003
  5. James Byrne
    Replies:
    3
    Views:
    625
    James Byrne
    Sep 14, 2010
Loading...

Share This Page