it forwarded me to page with "unreadable data"
comapred to the first example, you omit the
resp.setHeader("Content-Disposition", ...
here is the code ,i have the export method in a dispatch action :
public ActionForward exportSelectedIntaff(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) {
and i put this, after the creation of the excel file
try {
OutputStream out = response.getOutputStream();
FileInputStream fileStream = new
FileInputStream(filePath.replaceAll("/", "//"));
int bufferLen = 1024 * 8; // 8 KB
byte[] buffer = new byte[bufferLen];
while (true) {
int max = buffer.length;
int len = fileStream.read(buffer, 0, max);
if (len > 0)
out.write(buffer, 0, len);
else
break;
}
} catch (IOException e) {
// TODO: handle exception
}
Regards
Elyes
2008/12/16 Robert Graf-Waczenski <[email protected]>
> Hi Elyes,
>
> something like this here should work:
>
> OutputStream out = resp.getOutputStream();
> FileInputStream fileStream = new
> FileInputStream("path/to/your/excelFile.xls");
> int bufferLen = 1024 * 8; // 8 KB
> byte[] buffer = new byte[bufferLen];
> while (true) {
> int max = buffer.length;
> int len = fileStream.read(buffer, 0, max);
> if (len > 0)
> out.write(buffer, 0, len);
> else
> break;
> }
>
> Bye,
>
> Robert
>
>
>
> elyes sallem wrote:
>
>> Hello Robert ,
>> so assume that i have an excel file on the server
>> and i have a button to download it for the client (of course with a browse
>> dialog)
>> could you show me how develop it , in your example , you call
>> writePDFDataToOutputStream
>> and it is a pdf file which is not my case
>>
>> Thanks
>> Regards
>> Elyes
>>
>>
>>
>>
>>
>> 2008/12/15 Robert Graf-Waczenski <[email protected]>
>>
>>
>>
>>> Here's an example:
>>>
>>> public class Downloader extends HttpServlet
>>> {
>>> private void doGet(HttpServletRequest req, HttpServletResponse resp)
>>> throws
>>> IOException
>>> {
>>> resp.setHeader("Pragma", "no-cache");
>>> resp.setHeader("Cache-control", "no-cache");
>>> resp.setIntHeader("Expires", -1);
>>> MyData data = new MyData();
>>> resp.setHeader("content-type", "application/pdf");
>>> resp.setHeader("content-encoding", "binary");
>>> resp.setHeader("Content-Disposition", "attachment;
>>> filename=myfile.pdf");
>>> data.writePDFDataToOutputStream(resp.getOutputStream());
>>>
>>> }
>>> }
>>>
>>>
>>> elyes sallem wrote:
>>>
>>>
>>>
>>>> ok, do you have an example?
>>>>
>>>> Thanks
>>>> Regards
>>>> Elyes
>>>>
>>>>
>>>> 2008/12/15 Dave Newton <[email protected]>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>> --- On Mon, 12/15/08, elyes sallem wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> the problem is that with the html:file you must browse to an
>>>>>> existant file, but in my case, i wanna browse to a new file,
>>>>>> and then in the action i will make some treatment, generate
>>>>>> data and export them to this file
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>> That's not how you do that.
>>>>>
>>>>> You stream the response back and the user gets a save-file dialog.
>>>>>
>>>>> Dave
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: [email protected]
>>>>> For additional commands, e-mail: [email protected]
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>>
>>
>
>
--
Elyes.