Re: appendToResponse
Re: appendToResponse
- Subject: Re: appendToResponse
- From: "Daniele Corti" <email@hidden>
- Date: Tue, 17 Apr 2007 16:13:55 +0200
2007/4/17, WIESEN Bruno <email@hidden>:
Hello,
In my app, I create an excel sheet (with Jakarta POI) and I want to make it downloadable just after it has been created (the user has to click a button to create a file)
So i try to override appendToResponse like this but in the file there is some html tags...and not the content of the sheet created...
if(isExported)
{
super
.appendToResponse(response,context);
remove this! when you call super.appendToResponse() you generate an html header!
response.setHeader("inline; filename=" + fFileName,
"content-disposition");
response.setHeader(
"application/vnd.ms-excel", "content-type"
);
//Convert File to byte[]
try
{
response.setContent(
new NSData(convert("tmp" + fFileName)));
}
catch(Exception e)
{
NSLog.out.appendln(e.getMessage());
}
}
public
byte[] convert(String file)
throws Exception
{
File fichier =
new File(file);
InputStream in =
new FileInputStream(fichier);
byte[] tableau=
new byte
[in.available()];
in.read(tableau);
return
tableau;
}
look I use this:
File myFile = (File)this.session().objectForKey(GWSDownload.file);
try{
response.setContentStream(new FileInputStream(myFile), 4096, (int)myFile.length());
response.setHeader(""+myFile.length(), "Content-Length");
response.setHeader(WOApplication.application().resourceManager().contentTypeForResourceNamed(myFile.getName()), "Content-Type");
response.setHeader("attachment; filename=" + myFile.getName(), "Content-Disposition");
response.disableClientCaching();
response.removeHeadersForKey("Cache-Control");
response.removeHeadersForKey("pragma");
}catch(FileNotFoundException e){NSLog.out.appendln("File non trovato");}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (
--
Daniele Corti
AIM: S0CR4TE5
Messenger:
email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden