struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Gabriel Belingueres" <belingue...@gmail.com>
Subject Re: ServletOutputStream
Date Wed, 30 Jul 2008 17:58:43 GMT
A solution could be this: Store the excel data in session, then in
your 'status completed' page add an onload event to its body,
redirecting to the real download action:

IIRC:

<body onload="document.location.href='http://blahblah/myaction.action';">

You can also add a meta in the head:

<head>
    <META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://blahblah/myaction.action">
</head>

2008/7/30 Mike Rooney <okokabcde@yahoo.com>:
> Thank you for the reply.  I know my action can only return one response.  However I want
to avoid saving my file somewhere on the server and would like the 'File Download' dialog
to appear when the file is ready.  How can I do this in struts 2 while still forwarding to
a 'status completed' page? Would it be possible to store the file data in a session and somehow
have the File Download dialog show up?  If so I am not sure how to do that.
>
>
>
> ----- Original Message ----
> From: Gabriel Belingueres <belingueres@gmail.com>
> To: Struts Users Mailing List <user@struts.apache.org>
> Sent: Wednesday, July 30, 2008 3:59:29 AM
> Subject: Re: ServletOutputStream
>
> Your action can not generate two responses (if that's what you asking).
> If you forward to a 'status completed' page, then you need to save
> your excel data somewhere to not loosing it.
>
> 2008/7/29 Mike Rooney <okokabcde@yahoo.com>:
>> I created a small webapp that extracts data from a DB, creates an Excel file from
that data (using Apache POI), which then streams the file to the end user's browser.  Everything
is working fine, however I have to set the Action class' return type to 'NULL' since I am
setting the servlet response type to 'application/vnd-ms-excel'.  I want to change my application
so that it returns to a 'status completed' page when the extraction is completed. However
I cannot do this when I set the return type is null.  How can I do this?
>>
>> Here is my code...
>>
>> public class ExtractAction extends ActionSupport {
>>  public String execute() throws Exception {
>>    HSSFWorkbook wb = new HSSFWorkbook();
>>    HSSFSheet prodSheet = wb.createSheet("PROD");
>>    HSSFSheet devSheet = wb.createSheet("DEV");
>>    HSSFSheet testSheet = wb.createSheet("TEST");
>>    ...
>>    HttpServletResponse response = ServletActionContext.getResponse();
>>    response.setContentType("application/vnd.ms-excel");
>>    ServletOutputStream outstream = response.getOutputStream();
>>    wb.write(outstream);
>>    outstream.flush();
>>    response.flushBuffer();
>>  }
>>  return null;
>>  //return SUCCESS
>> }
>>
>> and my struts.xml
>>
>> <struts>
>>
>>  <constant name="struts.enable.DynamicMethodInvocation" value="false" />
>>  <constant name="struts.devMode" value="false" />
>>
>>  <package name="default" extends="struts-default">
>>    <action name="Extractor" class="action.ExtractAction">
>>      <result name="success">/example/index.jsp</result>
>>    </action>
>>  </package>
>>
>> </struts>
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message