RE: [OT] Storing files outside of the web context

2006-04-09 Thread Jesse Alexander \(KSFD 121\)



You could use a web.xml centext-param to pass the absolute 
path to the servlet.
 
In my experience the getRealPath()-method more often than 
not returns null. If you want to server resources from
a jar then use weblets. If you want to serve them from the 
filesystem use an absolute path configured via a 
system-setting of a context-param.
 
hth
Alexander

  
  
  From: Quintin Kerby [mailto:[EMAIL PROTECTED] 
  Sent: Friday, April 07, 2006 11:50 PMTo: MyFaces 
  DiscussionSubject: 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 
  KerbyCACI, Inc. 
  


  "James Reynolds" 
<[EMAIL PROTECTED]> 
04/07/2006 15:02 

  
  

  Please respond 
  to"MyFaces Discussion" 
  
  

  
  

  To
"MyFaces Discussion" 
   
  

  cc

  

  Subject
[OT] Storing files outside of the 
  web context

  
  

I have a jsf app that includes many .pdf files of contracts. 
   I've justbeen putting them all in the war before deploying to the 
  productionserver.  There must be a better way to do this.  Is it 
  possible to storethese files elsewhere on the web server, outside of the 
  context, andstill be able to link to 
  them?Thanks


RE: [OT] Storing files outside of the web context

2006-04-07 Thread James Reynolds
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()


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).


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" 
>
>
> To
> "MyFaces Discussion"  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



Re: [OT] Storing files outside of the web context

2006-04-07 Thread Matthias Wessendorf
be carefully, when using getRealPath()


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).


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" 
>
>
> To
> "MyFaces Discussion" 
> 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


RE: [OT] Storing files outside of the web context

2006-04-07 Thread James Reynolds

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" 


To
"MyFaces Discussion"  
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







Re: [OT] Storing files outside of the web context

2006-04-07 Thread Quintin Kerby

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" 





To
"MyFaces Discussion" 


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