Hi Kevin,
Could you please tell whether fileID means full path to the file or
something else ?
I want to pass file name as parameter. Where should I pass that ?
Regards,
A.P.Das.
Kevin Rutherford wrote:
>
> Hi Fred,
>
> You should not use a template (.vm) file because your extension of RawScreen
> is a "complete" response to a page request in Turbine. To access it, the URL
> should look something like:
>
> http://<server>:8080/app/servlet/app?screen=Download&fileID=12345
>
> Note the use of "screen" instead of "template", which tells Turbine to
> execute ONLY a screen class.
>
> To force the browser to display a "Save As" dialog box, you can set the
> content type to something that will not be recognized by the browser. For
> example, if your application is called "fred", you could return a content
> type of "application/fred-download" or something like that. If you want the
> browser to handle the file in some other way, such as displaying it in the
> browser window or launching a helper app, make sure you send the appropriate
> content type for the file, such as "text/plain" or "application/ms-word", or
> whatever.
>
> doOutput() looks something like this (but with exception handling, of
> course):
>
> public void doOutput(RunData data)
> throws Exception
> {
> // get the full path to the input file, based on the fileID, or whatever
> you use
> // to indicate what file is to be downloaded
>
> String filePath = ...
>
> // open the file for reading
>
> FileInputStream input = new FileInputStream(filePath);
>
> // open the response stream
>
> ServletOutputStream output = data.getResponse().getOutputStream();
>
> // tell the browser what the file name is so that the "save as" dialog
> does the
> // right thing (use the file name only, not the full path to the file!)
>
> String fileName = ...
> data.getResponse().setHeader("Content-Disposition", "inline; filename="
> + fileName);
>
> // copy the file content to the response stream
> // copy the file content from the input stream to the output stream
>
> int readCount;
> byte fileBuffer[] = new byte[FILE_BUFFER_SIZE];
>
> while((readCount = input.read(fileBuffer)) != -1)
> {
> output.write(fileBuffer, 0, readCount);
> }
>
> // close everything
>
> output.flush();
> output.close();
> input.close();
> }
>
> Hope that helps.
>
> Kevin
>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>