Results 1 to 5 of 5

Thread: Java Web Application Absolute/Relative Path

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    355

    Java Web Application Absolute/Relative Path

    Hi,

    I developed JSP using Netbeans (Apache Tomcat). I need to write out a file into a my project folder instead of the apache tomcat folder if I did not specify any path.

    I tried out.println(getServletContext().getRealPath("")); and it gives the path
    C:\Users\user\Desktop\project\build\web
    .

    How is it possible for me to change it to
    C:\Users\user\Desktop\project\web folder?

    Please advice, cheers

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Java Web Application Absolute/Relative Path

    This is the problem with your type of hobbiest programmers. Netbeans doesn't run the project from it's current location.. It deploys the web app to Apache tomcat and tries to launch it then. So, your application isn't actually in your C:\...\Desktop, hence the path C:\...\Desktop\... is an absolute path
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    355

    Re: Java Web Application Absolute/Relative Path

    Oh I see, so for this case, is it possible to enter the path correctly by using java built in method like getServletContext().getRealPath("") ?

    As this project is shared by different user, so when it is move to other PC, the path is different if I type my absolute path.

    As the getServletContext().getRealPath("") command return me C:\Users\user\Desktop\project\build\web, I would like to change it to
    C:\Users\user\Desktop\project\web instead, so I wonder is there other method I can use to achieve that or I must use substring to manually edit the path?

    Please advise

  4. #4
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Java Web Application Absolute/Relative Path

    If the file you're trying to point to is in the Netbeans project then you must know Netbeans deploys everything in the project to the Server
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2005
    Posts
    355

    Re: Java Web Application Absolute/Relative Path

    oh ok thanks for the information

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width