• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

jsp can't find file

 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pageContext.getServletContext()
 
Richard Scothern
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic