aspose file tools
The moose likes JSF and the fly likes Displaying an image in the jsp page from database. Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Displaying an image in the jsp page from database." Watch "Displaying an image in the jsp page from database." New topic
Author

Displaying an image in the jsp page from database.

Ravi Sankar
Ranch Hand

Joined: Aug 17, 2007
Posts: 49
Hi,

I want to display an image in the JSP page which is retrieved from the database. Do I need to have a getter/setter method in the Managed Bean? If yes, what will be the datatype for that property? If it is not needed, then how can i display that image in my jsp? I have given mycode which i implemented for your reference.
FacesContext context = FacesContext.getCurrentInstance();
HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();

// Write image contents to response.
response.setContentType("image/jpeg");
response.setContentLength(length);
response.getOutputStream().write(bytes);

When using this code, I am getting the image alone in the next page. I have to include this image in that jsp page. Please help me how to solve this?


Regards
Ravi
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 14487
    
    7

HTML 101:

Requests to a web server return a response of a single MIME type. In the event that that MIME type is "text/html", the returned page is expected to contain HTML elements. Some of those elements, such as IMG may contain URL refrerences themselves. In that event, additional requests are made by the browser to resolve those URLs. For the IMG element, that means that the URL should resolve to a MIME type of "image/xxxx", where "xxxx" is the encoding type, such as gif, jpeg or png.

The important thing here is that the image data is not embedded in the containing HTML, it's linked from the containing HTML. So the total number of requests made will be (at least) one for the page and one for each individual image on the page. Note that the image link doesn't have to refer to the same server or server app that the HTML came from. Or for that matter, that any other image, javascript or included CSS came from.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying an image in the jsp page from database.
 
Similar Threads
display image and text both on jsp page
displaying image in jsp from sql using helper servlet
Displaying Image
How to display a dynamic image along with other fields
File upload