• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Returning a PDF ByteArrayOutputStream to browser in Response

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my action class, I have a ByteArrayOutputStream that I want to return as the response to the browser.

I've tried creating a forward and putting this object in the session, but that clearly isn't how you'd do this.

Our action class method doesn't include an HttpServletResponse object as a parameter.

My quick check of an Action method shows that there IS an HttpServletReponse method there.

Can someone give me a suggestion on how to "hook" the response (in Struts)
from the action class?

Is the best (only) solution to add the HttpServletReponse object to the action's method that handles this request? In our case, our action class that processes the events isn't the "execute" method, but a post process method.

Shouldn't all action classes have access to the HttpServletResponse object?

So, in a nutshell, "How" best would I hook the Byte stream back to the browser without the Response object is my main question.

I'm trying to do this the "Struts" way if using the HttpServletResponse object isn't the "Struts way". (Using the response object works fine, however, if that's the Struts way too).

Thanks much for any suggestions!!!

M
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One possibility would be to write an Action class that extends the Struts DownloadAction and then forward to that action. For more information about the DownloadAction, see the Struts Javadoc

Otherwise, just use the HttpServletResponse object. The Struts forward mechanism was desined for HTML pages, and not for images or other files. There's nothing "un-Struts" about using the HttpServletResponse object. That's really all the DownloadAction does, but it just provides a mechanism that handles some of the nitty-gritty details for you.
[ May 30, 2007: Message edited by: Merrill Higginson ]
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Merrill,

Your responses are always so timely & excellent!!!

Mike
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic