Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Struts2 Image Display Replaces Response

 
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
 
Author
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]
 
Greenhorn
Posts: 11
  • 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
 
Men call me Jim. Women look past me to this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic