I'm working on a project in which, after the user submits a form, I'd like to have them download a PDF file (filled out with information from the form) as well as redirect them to another page. I know how to redirect (returning an ActionForward
which is set up to redirect to the correct JSP) and I know how to send the PDF (I build it using iText library, then write the byte array out to the HttpServletResponse
's output stream), but I'm not sure how to do both without some sort of kludge.
I'm guessing I'll have to do one of the two using javascript/ajax, but I was wondering if there is a more elegant way to do this with struts.
Not with servlets.
What I end up doing in these situations is request the file with a timestamp as a request parameter.
When I write the response I set a cookie with that timestamp. Every few moments on the client side I check to see if that cookie exists, if it does, I window.location to the 'redirect' page.