• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 Image Display Replaces Response

 
Dave Whaley
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic