You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by temp temp <mi...@yahoo.com> on 2006/01/18 16:17:12 UTC
file download problem
I am using struts action class to download a file .
Here is the action class
public ActionForward execute(ActionMapping aActionMapping, ActionForm aActionForm,
HttpServletRequest aHttpServletRequest, HttpServletResponse aHttpServletResponse)
throws Exception {
aHttpServletResponse.setContentType("application/octet-stream");
aHttpServletResponse.setHeader("pragma", "no-cache");
aHttpServletResponse.setHeader("Cache-Control","cache");
aHttpServletResponse.setHeader("Cache-Control","must-revalidate");
Integer aSysAttachId = new Integer(aHttpServletRequest.getParameter(IWeb.SYS_ATTACH_ID));
aHttpServletResponse.setHeader("Content-Disposition", "attachment; filename=\"" +aHttpServletRequest.getParameter(IWeb.FILE_NAME)+ "\"");
download(aApplicationInfoDelegate.getApplicationAttachemntFile(aSysAttachId),aHttpServletResponse);
return null;
}
private void download(byte[] byteArray, HttpServletResponse httpServletResponse)
throws IOException, SQLException {
try {
BufferedOutputStream aBufferedOutputStream =new BufferedOutputStream(httpServletResponse.getOutputStream());
aBufferedOutputStream.write(byteArray,0,byteArray.length);
aBufferedOutputStream.close();
} catch (Exception e) {
throw new IllegalArgumentException(e.getMessage());
}
}
My problem is with all ".doc "files and some ".pdf" files .When user clicks on the link , the browser opens a dialog box with the option to save or open the file .Suppose he has choosen a ".doc" file to open , the browser opens micorsoft word with an error message
Word experienced an error tying open the file.
Try these suggestions.
* Chaeck the file permissions for the document or drive.
* Make sure there is sufficient free memory and disk space
* Open the file with the text Recovery converter.
I also had other files like .xls and lot of .pdf and there is no problem with these files but with all .doc files.
Can Somebody guide with this issue.
Thanks & Regards
---------------------------------
Yahoo! Photos
Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.
Re: file download problem
Posted by Dakota Jack <da...@gmail.com>.
Just a thought. Isn't there a specific content type for .doc
documents? That might solve your problem.I looked it up. .doc
documents are "application/msword". Try that and see what happens. I
am actually building a list of all the extensions and their content
types. Hope this helps.
On 1/18/06, temp temp <mi...@yahoo.com> wrote:
> I am using struts action class to download a file .
>
>
> Here is the action class
>
> public ActionForward execute(ActionMapping aActionMapping, ActionForm aActionForm,
> HttpServletRequest aHttpServletRequest, HttpServletResponse aHttpServletResponse)
> throws Exception {
>
> aHttpServletResponse.setContentType("application/octet-stream");
> aHttpServletResponse.setHeader("pragma", "no-cache");
> aHttpServletResponse.setHeader("Cache-Control","cache");
> aHttpServletResponse.setHeader("Cache-Control","must-revalidate");
>
> Integer aSysAttachId = new Integer(aHttpServletRequest.getParameter(IWeb.SYS_ATTACH_ID));
> aHttpServletResponse.setHeader("Content-Disposition", "attachment; filename=\"" +aHttpServletRequest.getParameter(IWeb.FILE_NAME)+ "\"");
> download(aApplicationInfoDelegate.getApplicationAttachemntFile(aSysAttachId),aHttpServletResponse);
> return null;
> }
>
> private void download(byte[] byteArray, HttpServletResponse httpServletResponse)
> throws IOException, SQLException {
> try {
> BufferedOutputStream aBufferedOutputStream =new BufferedOutputStream(httpServletResponse.getOutputStream());
> aBufferedOutputStream.write(byteArray,0,byteArray.length);
> aBufferedOutputStream.close();
> } catch (Exception e) {
> throw new IllegalArgumentException(e.getMessage());
> }
> }
>
> My problem is with all ".doc "files and some ".pdf" files .When user clicks on the link , the browser opens a dialog box with the option to save or open the file .Suppose he has choosen a ".doc" file to open , the browser opens micorsoft word with an error message
>
> Word experienced an error tying open the file.
> Try these suggestions.
> * Chaeck the file permissions for the document or drive.
> * Make sure there is sufficient free memory and disk space
> * Open the file with the text Recovery converter.
>
>
> I also had other files like .xls and lot of .pdf and there is no problem with these files but with all .doc files.
> Can Somebody guide with this issue.
> Thanks & Regards
>
>
>
>
>
> ---------------------------------
> Yahoo! Photos
> Ring in the New Year with Photo Calendars. Add photos, events, holidays, whatever.
>
--
"You can lead a horse to water but you cannot make it float on its back."
~Dakota Jack~
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org