Thanks, I'll watch that. -----Original Message----- From: Matthias Wessendorf [mailto:[EMAIL PROTECTED] Sent: Friday, April 07, 2006 4:03 PM To: MyFaces Discussion Subject: Re: [OT] Storing files outside of the web context
be carefully, when using getRealPath() <snip> This method returns null if the servlet container cannot translate the virtual path to a real path for any reason (such as when the content is being made available from a .war archive). </snip> On 4/7/06, James Reynolds <[EMAIL PROTECTED]> wrote: > > Thank you so much. You don't know how much this helps :) > > ________________________________ > > From: Quintin Kerby [mailto:[EMAIL PROTECTED] > Sent: Friday, April 07, 2006 3:50 PM > To: MyFaces Discussion > Subject: Re: [OT] Storing files outside of the web context > > > > Absolutely. You could hard code a file path from inside a backing > bean and save the file anywhere on your system if you wanted. > > Here's some quick code I stole from one of my servlets that reads a > file from anywhere (just define your own filename) and sends it to the > response: > > ServletContext sc = getServletContext(); String filename = > sc.getRealPath("/images/bcg.gif"); > > // Get the MIME type of the image > String mimeType = sc.getMimeType(filename); if (mimeType == null) { > mimeType = "text/plain"; > } > > // Set content type > response.setContentType(mimeType); > > // Set content size > File file = new File(filename); > response.setContentLength((int) file.length()); > > //Set headers > response.setHeader("Content-disposition", "attachment; filename=" + > filename); response.setHeader("Cache-Control", "max-age=600"); > > // Open the file and output streams > FileInputStream in = new FileInputStream(file); OutputStream out = > response.getOutputStream(); > > // Copy the contents of the file to the output stream byte[] buf = new > byte[1024]; int count = 0; while ((count = in.read(buf)) >= 0) { > out.write(buf, 0, count); > } > in.close(); > out.close(); > > Quintin Kerby > CACI, Inc. > > > > "James Reynolds" <[EMAIL PROTECTED]> > > 04/07/2006 15:02 > Please respond to > "MyFaces Discussion" <users@myfaces.apache.org> > > > To > "MyFaces Discussion" <users@myfaces.apache.org> cc > > Subject > [OT] Storing files outside of the web context > > > > > > > > I have a jsf app that includes many .pdf files of contracts. I've > just been putting them all in the war before deploying to the > production server. There must be a better way to do this. Is it > possible to store these files elsewhere on the web server, outside of > the context, and still be able to link to them? > > Thanks > > > > > > -- Matthias Wessendorf Zülpicher Wall 12, 239 50674 Köln http://www.wessendorf.net mwessendorf-at-gmail-dot-com