File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp can't find file

 
Richard Scothern
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Richard Scothern
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64188
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pageContext.getServletContext()
 
Richard Scothern
Ranch Hand
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic