This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Servlets and the fly likes Image retrieval using the url Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Image retrieval using the url " Watch "Image retrieval using the url " New topic
Author

Image retrieval using the url

kulli putty
Greenhorn

Joined: Apr 11, 2013
Posts: 7

I have a database with images and I need to access the images in my project and display them in jsp page.
Newbee here i have no idea about getting image and displaying it in jsp page.
Everyone suggested going with creating a servlet and getting the image file.
Can anyone help me with this???
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
Important point:

You don't "display in a jsp page" - you use JSP to write an HTML page that has an <IMG tag that provides the information needed for a servlet to retrieve and send the binary image data. <br /> <br /> GETing the image data is a separate request/response cycle just like GETing every other resource that makes up an HTML page. <br /> <br /> Bill <br /> <br /> >


Java Resources at www.wbrogden.com
Syed Ali
Greenhorn

Joined: Oct 08, 2008
Posts: 29
you need image servlet to display the images in the jsp , the following line you need in the jsp to get image from the image servlet



image is the image servlet , you also need an entry in the web.xml for image servlet
Syed Ali
Greenhorn

Joined: Oct 08, 2008
Posts: 29
you need image servlet to display the images in the jsp , the following line you need in the jsp to get image from the image servlet

<!-- <img src="image?id=${Model.Member.id_member}&domain=Member" height="100" /> -->

image is the image servlet , you also need an entry in the web.xml for image servlet
kulli putty
Greenhorn

Joined: Apr 11, 2013
Posts: 7

Hi ,

Thank you for your response.William Brogden & syed ali.
But i dont know how to write a servlet for fetching the image and displaying in the screen.
In my jsp page the number of images depend on certain conditions so the number of images fetched is unknown each time.
I have js for retriving the url location and number of images i need to fetch from the db.
How do i wade further....with the location of image.

Please help me.....
kulli putty
Greenhorn

Joined: Apr 11, 2013
Posts: 7




This way i havin a radio button for each image but i dont know how to get the image.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60072
    
  65

The src URL of the tag should be the URL of a servlet that serves the image data as the response. Be sure that the servlet sets the appropriate response headers.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
kulli putty
Greenhorn

Joined: Apr 11, 2013
Posts: 7

@Bear Bibeault

thank you for replying.

Based on your answer I went through servlet mapping.And I got better understanding of servlets.

But can you help me in how to invoke the servlet from js file where i want to fetch the image.

You said the src should be URL tag of a servlet
I did not understand how should the url be. Any examples or link which i can refer will be helpful in better understanding.

Thank you for taking time to help me .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60072
    
  65

WHat is the mapping that invokes the servlet? Hope did you map it in the deployment descriptor?

Whatever that is is what you'll use for the image tag src value. This has absolutely nothing at all to do with JSP.
kulli putty
Greenhorn

Joined: Apr 11, 2013
Posts: 7

Thank you for sparing your time I got help else where.
And yes i had done the mapping.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60072
    
  65

So you have posted this elsewhere? Please read BeForthrightWhenCrossPostingToOtherSites
kulli putty
Greenhorn

Joined: Apr 11, 2013
Posts: 7

Im sorry bear but i have to correct you there are tutorials through which we can learn and gain knowledge if anyone can help with solutions for a particular problem is the reason they post question in forum.
I serched understood and tried implementing. ("And i never asked for ready made code all i asked is guiding a horse to water drinking it is left to me." - You can ignore this if it hurts your ego )
FYI = For your information
i haven't done "CrossPosting" i just learned Java Servlets better through free tutorials.
From my question itself you should have understood that i had little knowledge about servlets ,
You tried to help me I appreciate it.Thanks for it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Image retrieval using the url
 
Similar Threads
getting the field values of a dyanamically updated table
Issue with html:img
displaying images from databse
page content type
How to display more number of images in a jsp page ?