Re: read local file in ActionStruts

I do something like this in one app... 

I'm creating PDFs on-the-fly and then displaying them on the browser.  I have a 
directory named temp under my webapp that the PDFs get written to.  The files 
are named according the the user ID.

You have the Action writing out the file already... if we assume you also name 
it according to user ID, here's how to do it...

(1) Make sure your Action adds the user ID to request as an attribute

(2) Add the following forward to your ActionMapping (changing the path 
accordingly of course):

  <forward name="defaultForward" path="/jsp/showPDF.jsp" />

Naturally, be sure your Action returns this forward.

(3) Add showPDF.jsp to your webapp.  Here it is:

  <%@ page language="java" import="java.util.*" %>
  <%
    String url = "http://";;
    url += request.getServerName();
    url += ":";
    url += request.getServerPort();
    url += "/myApp/temp/";
    url += (String)request.getAttribute("userID");
    url += ".pdf";
  %>
  <html>
  <head>
    <title>Show PDF</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="expires" content="0">
  </head>
  <body onLoad="window.location='<%=url%>';">
    Retrieving PDF for display...
  </body>
  </html>

That's it.  Does the trick for me, nice and simple.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Tue, February 1, 2005 9:12 am, [EMAIL PROTECTED] said:
> could u be more precise?
> U mean to save there the file and after that read it?!
> Actually I did not find any instructions.
> Do u?
> 
> 
> --------- Initial Header -----------
> 
>>From      : [EMAIL PROTECTED]
> To          : "Struts Users Mailing List" user@struts.apache.org
> Cc          :
> Date      : Tue, 1 Feb 2005 09:06:51 -0500
> Subject : Re: read local file in ActionStruts
> 
>> How about using the javax.servlet.context.tempdir Servletcontext
>> attribute?
>>
>> Dennis
>>
>>
>> Keshav Shetty <[EMAIL PROTECTED]>
>> 02/01/2005 08:52 AM
>> Please respond to
>> "Struts Users Mailing List" <user@struts.apache.org>
>>
>>
>> To
>> Struts Users Mailing List <user@struts.apache.org>
>> cc
>>
>> Subject
>> Re: read local file in ActionStruts
>>
>>
>>
>>
>>
>>
>> Then don't store the file within webapp, but in any server folder and
>> write a servlet to retrieve the file.
>>
>> Thanks & regards
>> Keshav K Shetty
>>
>> [EMAIL PROTECTED] wrote:
>>
>> >Tomcat  see a new created file only after shutdown and startup.
>> >That's a big problem.
>> >Help!
>> >
>> >---------- Initial Header -----------
>> >
>> >>From      : "Keshav Shetty" [EMAIL PROTECTED]
>> >To          : "Struts Users Mailing List" user@struts.apache.org
>> >Cc          :
>> >Date      : Tue, 01 Feb 2005 15:36:06 +0200
>> >Subject : Re: read local file in ActionStruts
>> >
>> >
>> >
>> >>You can store the file on sever and not in client.
>> >>If I understood you already created file in your struts action and
>> >>stored in the server.
>> >>So instead of giving file:// use full link with http:// link to file.
>> >>(Hope the file is within webapp) or write your download servlet.
>> >>
>> >>Thanks & regards
>> >>Keshav
>> >>
>> >>[EMAIL PROTECTED] wrote:
>> >>
>> >>
>> >>
>> >
>> >
>> >
>> >>>Hi all
>> >>>In an Action Struts I create dynamically a file.
>> >>>After that whit PrintWriter I try to get the file win a script tag
>> (<script>document.location='file:///xxx.xx'</script>)
>> >>>My problem is IE or Netscape does not allow me to read local file.
>> >>>Any alternative idea?
>> >>>
>> >>>
>> >>>
>> >
>> >
>> >
>> >>>
>> >>>____________________________________________________________
>> >>>6X velocizzare la tua navigazione a 56k? 6X Web Accelerator di
>> Libero!
>> >>>Scaricalo su INTERNET GRATIS 6X http://www.libero.it
>> >>>
>> >>>
>> >>>
>> >>>---------------------------------------------------------------------
>> >>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >>>
>> >>>
>> >
>> >
>> >
>> >>>For additional commands, e-mail: [EMAIL PROTECTED]
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>---------------------------------------------------------------------
>> >>To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >>For additional commands, e-mail: [EMAIL PROTECTED]
>> >>
>> >>
>> >>
>> >>
>> >
>> >
>> >
>> >____________________________________________________________
>> >6X velocizzare la tua navigazione a 56k? 6X Web Accelerator di Libero!
>> >Scaricalo su INTERNET GRATIS 6X http://www.libero.it
>> >
>> >
>> >
>> >---------------------------------------------------------------------
>> >To unsubscribe, e-mail: [EMAIL PROTECTED]
>> >For additional commands, e-mail: [EMAIL PROTECTED]
>> >
>> >
>> >
>> >
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
> 
> 
> 
> ____________________________________________________________
> 6X velocizzare la tua navigazione a 56k? 6X Web Accelerator di Libero!
> Scaricalo su INTERNET GRATIS 6X http://www.libero.it
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to