• 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

How do I use a servlet instead of jsp as the view for returning binary image data?

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Referring to section 3.5.1 of this page: http://struts.apache.org/1.x/userGuide/building_view.html

That talks about using a servlet to render binary image data.

Right now, I have my binary image data being written in a JSP, which is sort of fine.

But I'd rather do this in a servlet, because the JSP markup is useless here.

How do I set that up? Is there some magic in struts.xml? Do I need to play with the controller?

All help appreciated,
Colin Freas

 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't go through that page that you pointed out, but you can use a servlet as a view just like you use a JSP. Just use the appropriate mapping in the struts-config.xml

 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Normally you'd just write to the response, and return a null in Struts 1, or a null or ActionSupport.NONE in Struts 2 (it's handy to specify which version you're using :)
 
Colin Freas
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanks for the replies, gents. btw: Struts 1.

So, I'm trying to figure out the Struts-iest way of doing what I'm doing.

I have a page with some charts on it. I have the action, the form, and the jsp for the page containing the charts. The charts themselves are images and html image maps generated by JFreeChart. So, I need the image map markup included in the jsp, and I need the binary image data in the response to the request from the <img> src attributes.

For argument's sake, let's say I don't want to have the forward to the servlet as Ankit suggest. I see how this is a completely viable solution, but this is the only point in the application where that technique would be used, which could make for maintenance problems later.

So, thinking about this, I wondered if the following makes sense, vis-a-vis the Struts MVC paradigm. I put the methods that generate the binary image data into the form class. The chart action then calls those methods, and overrides the normal response, when a parameter is set in the request.

So... does that make sense? Is that the Struts-iest way to do this?

-Colin
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wouldn't put any image generation code into the ActionForm, that strikes me as bizarre. ActionForms are a DTO between the web page and Struts. (Some people use them to pass non-form data, I don't--YMMV). I'd put the chart generation code into a service object, inject it into an action, and use that action as the URL for the image tag.
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic