I suppose there is a lot of other way to generate pdf with struts2. Certainly a plugin. But I don't know how it works.

However, to invoke a jsp and get the result in your action, you can use a requestDispatcher to obtain the resut of a jsp execution.

Here is something I already done with struts1. I have problems now with struts2's request dispatcher. So I don't know if it still work ...


request.setAttribute("param1", valuepram1);
...
Eventally, had a path to an embeded image :
request.setAttribute("logo", MyActionClass.class.getClassLoader().getResource("/path/to/th/logo.gif").getFile());

ResponseWrapper responseWrapper = new ResponseWrapper(response);


getServlet().getServletContext().getRequestDispatcher("path/to/the/fop-jsp.jsp").include(request, responseWrapper).include(request, responseWrapper);

you can use now
byte[] bytes = responseWrapper.getBytes();
to get the file generated by the jsp.


responseWrapper is a simple class like :


public static class ResponseWrapper extends HttpServletResponseWrapper {

        private ByteArrayOutputStream baos = new ByteArrayOutputStream();
        private ServletOutputStream sos = new ServletOutputStream() {
                        public void write(int b) throws IOException {
                                baos.write(b);
                        }
        };
private PrintWriter osw = new PrintWriter(new OutputStreamWriter(baos));
                public ResponseWrapper(HttpServletResponse response) {
                        super(response);
                }

public ServletOutputStream getOutputStream() throws IOException {
                        return sos;
                }

                public PrintWriter getWriter() throws IOException {
                        return osw;
                }

                public byte[] getBytes() {
                        osw.flush();
                        return baos.toByteArray();
                }

    }

Hoying, Ken a écrit :
I could use some advice from some folks with more experience and
knowledge of Struts2 than I to assist me in determining the correct way
(or lay out some viable options) to design a solution for the following
senario:

We need to generate a PDF report real time based on data in a database
that is available for download.  What we believe that we would like to
do is utilize FOP (http://xmlgraphics.apache.org/fop/) and use a JSP
page to actually generate the formatting objects and then run the
formatting objects through the FOP processor to generate and stream the
PDF back to the user.
However, we are not real sure how to implement this in Struts2.  How do
we invoke the JSP page and then get access to the results?  Do we just
use the stream result type and then use a http call to the JSP as the
input source?  This would seem like it would not be optimal from a
performance standpoint, as we are making another http call to get the
formatting objects from the jsp.  It also adds the complexity of passing
security credentials in the call.  Or do we need to somehow create or
own result type and if so how do we get those JSP results?  I have not
really found any good documentation or example on writing your own
result types.

Thanks in advance!



-----------------------------------------
***Note:The information contained in this message may be privileged
and confidential and protected from disclosure. If the reader of
this message is not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient,
you are hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited. If you have
received this communication in error, please notify the Sender
immediately by replying to the message and deleting it from your
computer. Thank you. Premier Inc.

--

Mike Baroukh

---
Cardiweb  - 31 Rue de Mogador Paris IXeme
06 63 57 27 22 - 01 53 21 82 63 - Jabber: [EMAIL PROTECTED]
http://www.cardiweb.com
---


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

Reply via email to