This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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 :)
Joined: Aug 11, 2009
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?
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.