We do a similar thing to return map images in gif and png format:

Action mapping (note, no forward):

    <!-- Map Image Request -->
    <action    path="/mapImage"
        type="com.ofx..action.MapImageAction">
    </action>

MapImageAction:

      // Make sure images are not cached on client or
      // else panning/zooming will not go get a new image.
      // These values ARE case sensitive and must be exactly as below:
      response.setHeader("Pragma", "No-cache");
      response.setHeader("Cache-Control", "no-cache");
      response.setDateHeader("Expires", 1);

      response.setContentType(contentType);
      ServletOutputStream os = response.getOutputStream();
      os.write(imageBytes, 0, imageBytes.length);
      os.flush();
      os.close();

      // Do not forward this request as we have already sent the bytes back
      // to the client.
      return null;
      // I tried having a jsp page return the image bytes, but this
      // resulted in a JSP "IllegalStateException".

JSP Page:
    ...
    <image src="/mapImage.do">
    ...

Nathan.

 -----Original Message-----
From:   Jeremy Nix [mailto:[EMAIL PROTECTED] 
Sent:   Wednesday, March 26, 2003 8:58 AM
To:     [EMAIL PROTECTED]
Subject:        Returning a different request-type (xml/pdf/doc/etc...)
through Struts

I am new to struts, and have just recently began porting our current web
application over to the struts framework.  A piece of our application
involves creating a pdf file and displaying it to the user.  Currently,
in the old framework, we set the ContextType of the response, and write
the byte content to the response's oputputstream, which will render the
pdf document in the browser.  I know I have direct access to the
response under Struts, but I wanted to see if there was a better
(cleaner) implementation within the struts framework that I may utilize.

Here's a snippet of what I'm doing:
---
response.setContentLength(doc.getContent().length);
response.setContentType(doc.getMimeType().toString());
response.getOutputStream().write(doc.getContent());
return new ActionForward();
---

I've noticed that I get a NullPointer exception after the return
statement on "some" requests.  I'm really unsure of why this is
happening as well.

Stack trace:
java.lang.NullPointerException at
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestPr
ocessor.java:437) at
org.apache.struts.action.RequestProcessor.processActionForward(RequestPr
ocessor.java:401) at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:
279) at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1420)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:520)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

_________________
Jeremy Nix
Senior Application Developer
Southwest Financial Ltd.
[EMAIL PROTECTED]
(513) 621-6699 ext 1158


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

Reply via email to