On Thu, 2004-09-16 at 19:49, Joe Hertz wrote:
> Absolutely. You have access to all of the response object methods you would
> in a servlet to do this with.
>
> Set the correct content type and content length headers and spit it to the
> outputstream. Return a null findForward.
>
> I've done this with pdf files, (and this week I asked on this list about img
> tags. Was even easier: It worked the same way, but with none of the header
> setting apparently. Least I hope so :-).
>
> In fact, the file doesn't even need to be accessible via a browser
> accessible URL. If the application can read it, that's all you need.
So, you mean something like this?
public class FileXferAction extends Action {
public ActionForward execute(
ActionMapping actionMapping, ActionForm actionForm,
ServletRequest servletRequest, ServletResponse servletResponse )
throws Exception {
System.out.println( "Here we are!" );
OutputStream os = servletResponse.getOutputStream();
os.write( "Content-Type: application/pdf\n".getBytes() );
FileInputStream fis = new FileInputStream( "/tmp/test.pdf" );
int len;
byte[] bytes = new byte[1024];
while ((len = fis.read( bytes )) > 0) {
os.write( bytes, 0, len );
}
fis.close();
return null;
}
}
Unfortunately that just gives me a blank screen. Importantly, "Here we
are!" does NOT show up in the log, so . . . apparently the action isn't
even getting invoked. Probably something to do with struts-config.xml:
<action path="/xferFile"
type="action.FileXferAction"
validate="false"/>
I just guessed at this. Since it doesn't forward, doesn't use a JSP
page, etc, I'm leaving those attributes empty. If they shouldn't be
empty, what should they be?
Mike
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]