wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts2 Image Display Replaces Response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 Image Display Replaces Response" Watch "Struts2 Image Display Replaces Response" New topic
Author

Struts2 Image Display Replaces Response

Dave Whaley
Greenhorn

Joined: Aug 07, 2003
Posts: 5
I was able to display an image feed from a byte stream in my JSP using these instructions: Struts FAQ Dynamic Image Example.

However, the rest of my JSP output does not show. In other words, the HTML my browser displays is replaced by only an image. I would like to know a) how to fix it, and b) what is going on in general. Is it that the MyBytesResult class causes some sort of redirect when it does "response.getOutputStream().write(action.getImageInBytes());" ? Why is not the image inserted into my rendered page instead of replacing it? Any ideas?

Wildman
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Consider how an HTML page normally displays an image: the image data isn't embedded in the HTML.

Instead, an HTML image tag is used to request the image from the server--that's how your JSP page should work as well. Don't combine the two.
Dave Whaley
Greenhorn

Joined: Aug 07, 2003
Posts: 5
David Newton wrote:Consider how an HTML page normally displays an image: the image data isn't embedded in the HTML.Instead, an HTML image tag is used to request the image from the server--that's how your JSP page should work as well. Don't combine the two.

That helped. I am a little too tired to figure out how to explain what I was doing wrong, but basically the example shown is correct. I was thinking that the <img src> tag would do its call after the JSP was displayed. Instead, I changed the mapping to directly invoke the result-type mechanism.

[Ankit: disabled HTML in the message]
Aruna Ponaka
Greenhorn

Joined: Dec 08, 2009
Posts: 9
Hi,

am building an application using struts 2 and tiles. The image rendering example is not working for me. The application is not throwing an error but not displaying the image. Instead of <img src="/myWebAppContext/myAction.do" /> if I use <img src="<s:url action="myAction"/>" />, it throws an error saying

No result defined for action com.action.MyAction and result success.

Did you write any myImageResult.jsp. My result must go to books.jsp but it is tiles page, if I change <result name="myImageResult" type="myBytesResult" /> to
<result type="myBytesResult" > books </result>, it does not work as my books page is defined in type="tiles".

If interested will give more details of the code.

Thanks,
Aruna
 
GeeCON Prague 2014
 
subject: Struts2 Image Display Replaces Response