GeeCON Prague 2014*
The moose likes JSP and the fly likes jsp can't find file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "jsp can Watch "jsp can New topic
Author

jsp can't find file

Richard Scothern
Ranch Hand

Joined: May 25, 2001
Posts: 83
Hi all,
I've created a jsp page that takes a parameter (url) which is the string representation of a file location so I can manipulate the file in a custom tag.
I'm finding it impossible to access files stored on the server becuase the default directory seems to be <tomcat install dir>/bin.
So if my GET request looks like this:
.../jsp/phone.jsp?url=index.wml
I am catching a FileNotFoundException which thinks the file is in
c:/java/jakarta-tomcat-3.2.3/bin/index.wml
when the file is actually in the same directory as phone.jsp
Is there something I can do to change the default directory, perhaps within server.xml? I'm running tomcat 3.2.3 on Windows 2000.
Thanks,
Richard
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

If you know the relative to path to the file (which I am assuming since you know it's in the same folder as one of your JSPs), you can use the getRealPath() method from ServletContext to get the absolute path of the file in the filesystem.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Richard Scothern
Ranch Hand

Joined: May 25, 2001
Posts: 83
I know the relative path of the file, but I'm doing stuff with the file in a JSP custom tag.
How do I get the ServletContext from this page.
Thanks,
Richard
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

pageContext.getServletContext()
Richard Scothern
Ranch Hand

Joined: May 25, 2001
Posts: 83
Ah! Thanks for your help, Bear. I figured out the last answer about 10 minutes after I made the post, lazyness on my part.
Richard
 
GeeCON Prague 2014
 
subject: jsp can't find file