You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by horshaq <ma...@roomity.com> on 2005/10/13 17:07:53 UTC

not working when sending a file to client with struts.

Hello, this is my first post here.  I am pretty new to struts and have wasted a ton of time trying to figure out why my error messages (using ActionErrors) were not getting displayed on my .jsp page.

After commenting out all of my code, i've realized it has to do with the following lines of code.

response.setContentType("application/octect-stream");
response.setHeader("Content-Disposition", "attachment; filename=" + zipFileName);
response.setContentLength((int)tempCSVFile.length());

As part of the app i need to send a zip file back to the users which contains one or many csv files (the file sends np).  I need to return this file along with any errors in creating the csv files.  I'm finding that my ActionErrors do not get returned to my .jsp file after calling the setHeader method and changing the header.  Does anyone have any suggests on how to best to return errors to the user keeping in mind I already have a .jsp coded with html:errors tags waiting for the errors?  Can both of these tasks be accomplished together?

I'm supposed to have the errors displaying by tomorrow, so quick responses would be greatly appreciated :)

Thanks in advance.


-------------------------------------------------------------
<a href="http://Struts_User_List.roomity.com">roomity.com</a>
Your Roomity Broadband Webapp ~~1129216073404~~
-------------------------------------------------------------

Re: not working when sending a file to client with struts.

Posted by Kishore Senji <ki...@gmail.com>.
> file along with any errors in creating the csv files. I'm finding that my
> ActionErrors do not get returned to my .jsp file after calling the setHeader
> method and changing the header. Does anyone have any suggests on how to best
> to return errors to the user keeping in mind I already have a


>From you action after setting the headers and I assume you also write the
Zip file contents to the OutputStream how are you going back to the JSP. I
guess you might be returning null, which indicates to Struts that the
response is taken care of by the Action and so does nothing afterwards.

I guess what you might want to do is that from a jsp, when the user clicks
on the download link go to an action, which composes the errors and takes
the user to another page which shows the errors (if any) and sends a request
for the file to be downloaded through <META> tags.

Re: Re: not working when sending a file to client with struts.

Posted by Simons Kevin <fb...@skynet.be>.
horshaq can you provide some details. I just spent four hours! on just 
getting a simple validation going!... But perhaps I can help you.
----- Original Message ----- 
From: "horshaq" <ma...@roomity.com>
To: <us...@struts.apache.org>
Sent: Thursday, October 13, 2005 9:39 PM
Subject: Re:<html:errors> not working when sending a file to client with 
struts.


> Nobody?
>
> I've searched the web for the past few hours and can't seem to find 
> anything related this topic.  I can't be the only one to have this problem 
> occur.
>
> I should also mention that i've try using <html:messages> as well and they 
> don't show up either.
>
> Someone must know the answer, please speak up if you do.
>
> Thanks,
> Jonathan.
>
>
>
> -------------------------------------------------------------
> <a href="http://Struts_User_List.roomity.com">roomity.com</a>
> Your Roomity Broadband Webapp ~~1129232374915~~
> -------------------------------------------------------------
>


--------------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.14/131 - Release Date: 12/10/2005



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.11.14/131 - Release Date: 12/10/2005


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


Re: not working when sending a file to client with struts.

Posted by horshaq <ma...@roomity.com>.
Nobody?

I've searched the web for the past few hours and can't seem to find anything related this topic.  I can't be the only one to have this problem occur.

I should also mention that i've try using <html:messages> as well and they don't show up either.

Someone must know the answer, please speak up if you do.

Thanks,
Jonathan.



-------------------------------------------------------------
<a href="http://Struts_User_List.roomity.com">roomity.com</a>
Your Roomity Broadband Webapp ~~1129232374915~~
-------------------------------------------------------------

Re: not working when sending a file to client with struts.

Posted by Kishore Senji <ki...@gmail.com>.
> response.setContentType("application/zip");
> response.setHeader("Content-Disposition", "attachment; filename=" +
> zipFileName);
> response.setContentLength((int)tempCSVFile.length());
> BufferedInputStream bufferedInput = new BufferedInputStream(new
> FileInputStream(tempCSVFile));
> BufferedOutputStream bufferedOutput = new BufferedOutputStream(
> response.getOutputStream());
>
> while((leftToRead = bufferedInput.read(buffer)) != -1) {
> bufferedOutput.write(buffer, 0, leftToRead);
> }
>
> bufferedInput.close();
> bufferedOutput.flush();
> bufferedOutput.close ();
>
> if(!errors.isEmpty()) {
> saveErrors(request, errors);
> return(mapping.findForward("fail"));
> }
>
> return (mapping.findForward("success"));


I don't think it's anything to do with Struts. You just set the
content-length header, which tells the servlet container how much the
response body length would be. If you try to write more stuff into it, I'm
not sure it would get written to the response.

Re: not working when sending a file to client with struts.

Posted by horshaq <ma...@roomity.com>.
Thanks for responding.

>>From you action after setting the headers and I assume you also >write the Zip file contents to the OutputStream how are you going >back to the JSP. 

Yes, i do the following:

response.setContentType("application/zip");
response.setHeader("Content-Disposition", "attachment; filename=" + zipFileName);
response.setContentLength((int)tempCSVFile.length());
BufferedInputStream bufferedInput = new BufferedInputStream(new FileInputStream(tempCSVFile));
BufferedOutputStream bufferedOutput = new BufferedOutputStream(response.getOutputStream());
          
while((leftToRead = bufferedInput.read(buffer)) != -1) {
      bufferedOutput.write(buffer, 0, leftToRead);
}
          
bufferedInput.close();
bufferedOutput.flush();
bufferedOutput.close();

if(!errors.isEmpty()) {
      saveErrors(request, errors);
      return(mapping.findForward("fail"));
}

return (mapping.findForward("success"));

I create errors earlier in the class, for example:
error = new ActionError("error.ExportAction.domainError");
errors.add("exportDomainError", error);

The errors get output to my jsp file if i have the code related to sending the zip file commented out.  When it isn't comment the file gets sent back properly but i get no errors sent back to the jsp.  Is this normal for struts?

>I guess what you might want to do is that from a jsp, when the >user clicks on the download link go to an action, which composes >the errors and takes the user to another page which shows the >errors (if any) and sends a request for the file to be downloaded >through <META> tags.

I was thinking of doing something like this, but was hoping i didn't have to.  Can anyone confirm that i can't send both ActionErrors(or ActionMessags) and a file back to the client?

Jon.


-------------------------------------------------------------
<a href="http://Struts_User_List.roomity.com">roomity.com</a>
Your Roomity Broadband Webapp ~~1129238460128~~
-------------------------------------------------------------