This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading file from server into browser window

 
Richard Elsberry
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm developing and jsp, with some struts, application and am required to keep a folder of image and pdf files outside the application context and on the server - ie c:\files\load. The files need to reside outside the application so that they are not wiped out when a new war file is deployed. I've done this many times for an images folder or something from within the app but can't figure out how to do this from the file system. Anybody know how this is done?

Thanks,
Richard
 
Stefan Evans
Bartender
Pie
Posts: 1670
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Normally you use a servlet to handle this.

You use the java.io File access methods to load the image/pdf files, and then stream it out via the ServletOutputStream.

So the call to load the resource would be

<a href="servletLoader?file=myImage.gif"> My Image </a>
Based on the parameter, you load the appropriate file from the c:\files\load directory. I would probably make that a paramter in the web.xml so you could change that easily if necessary.

Hope this helps,
evnafets
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64629
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please do not post the same question more than once.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic