Rather than go into all the details, here is the nuts and bolts of doing this from within an Action.

In your Action class' execute implementation, your goal here is not to return an ActionForward as you typically do. You need to have a little bit lower level control over the HTTP response to serve binary content from within a Struts app. So you will set some response headers (including the MIME type), transfer the data 1 byte at a time (or one buffer at a time) from the local Word file (using a FileInputStream or similar) to the response's output stream, close the stream yourself, and then return null from your execute method, to let the Struts controller know the Action has handled the response on its own and that no forwarding will be required (nothing else need be written to the stream). This all assumes that the user has been provided a link to the file that contains some sort of token your Action can use to find the correct file on a protected area of the local filesystem (rather than a link directly to a file in your web server public doc root).

MIME type lists can be found on the Web. I think it's something like "application/ms-word" but I can't remember. The use is:

response.setContentType("application/ms-word");

or you can use setHeader directly.

Various other response headers (content length, content disposition -- which should let you control whether you want a new browser window, caching, etc.) probably will be useful to you. Their use can be researched on the Web (on this list too but it has been a while) and is not particular to Struts.

Hope that helps,
Erik





[EMAIL PROTECTED] wrote:

what i want is open direcltly in a  new browser the WORD document?
---------- Initial Header -----------

From : [EMAIL PROTECTED]
To : "Struts Users Mailing List" user@struts.apache.org
Cc : Date : 26 Jan 2005 16:38:01 +0100
Subject : Re: redirectig to WORD files




"[EMAIL PROTECTED]" <gdilem 'at' libero.it> writes:



Hi all I try to redirect my response to a word doc file.But after
setting contexttype and using response.sendRedirect(docWordURL) , I
get white page; What I want is open this word document on a click of a
link in a normal jsp.I call the action that has to redirecting me to
that file. Any idea? Regards


Try

       response.setContentType( "whatever_suitable_for_msword" );

response.setHeader( "Content-Disposition", "attachment; filename=foo.doc" );

Then write to response.getWriter(). Worked for me.

--
Guillaume Cottenceau

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







____________________________________________________________ 6X velocizzare la tua navigazione a 56k? 6X Web Accelerator di Libero! Scaricalo su INTERNET GRATIS 6X http://www.libero.it



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to