• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

problem in fetch the images from database.

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




I created this servlet and try to find out the images in local disk d's test folder from database, but images did not fetch in folder why?
 
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll need to give us more information that that. Have you used logging or other techniques to debug where the method is going awry?

And rt1 is not an appropriate class name.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

this is servlet where I have inserted images in database........







and when I try to fetch only one image then no problem it fetched like this.


 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You'll need to give us more information that that. Have you used logging or other techniques to debug where the method is going awry?


You have not put forward any new information on the nature of the problem. Are you getting a connection? Are you getting anything back from the database? What debugging have you done?

And rt1 is not an appropriate class name.


Please use appropriate naming conventions. Code that does not follow the naming conventions is surpassingly hard to read. Class names should be complete words and start with an uppercase letter.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got nothing from database, see in image and also my local disk d's folder is empty.
Screenshot_4.png
[Thumbnail for Screenshot_4.png]
Screenshot_5.png
[Thumbnail for Screenshot_5.png]
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, of course you're not going to see anything in the browser -- you are writing to a file.

Are you looking for the file in the right place?

And you still haven't answered by questions? Connection? Resultset length? Any exceptions being thrown?

Add logging to your servlet if you are not set up to step though a debugger.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code, I posted in which the line (OutputStream outputStream = new FileOutputStream(new File("D:/test1" + i + ".jpg"));) is retrieve images from database and store in local disk D, yes I got images in local disk D, but from there , I can not fetch and display images in jsp, so now I want these images in my java project's web container, (and ofcourse, I can not copy and paste, because I insert and store images dynamically at user request), so in that case I changed my path like (OutputStream outputStream = new FileOutputStream(new File("/jewellery/WebContent:/test1" + i + ".jpg"));), but I could not find any image in WebContent folder, it shows me error filenot found, how will this possible???
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why are you even writing a file to the disk? If your aim is to display it in a JSP page, the image should be written as the response to a servlet, not written to a file. The image tag in the JSP would reference the servlet.

Perhaps looking through the ServletsFaq at this article https://coderanch.com/t/660125/Wiki/Image-Servlet would be helpful.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can not figure out, means, instead of this line (OutputStream outputStream = new FileOutputStream(new File("D:/test1" + i + ".jpg"));), which line should I write? because, I need to store images somewhere right? and I know to display only one image in jsp by img tag, but how I display multiple images in jsp by img tag?
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sarojni agrwal wrote:I can not figure out, means, instead of this line (OutputStream outputStream = new FileOutputStream(new File("D:/test1" + i + ".jpg"));), which line should I write?


Did you read the FAQ article I took the time to link to?

because, I need to store images somewhere right?


No. Why does it need to be stored anywhere? All that needs to happen is for the image data to get sent to the HTML page. It doesn't need to be in a file for that.

and I know to display only one image in jsp by img tag, but how I display multiple images in jsp by img tag?


You display more than one image with more than one img tag. Or are you asking about something different?

Read the FAQ article. You seem to be under the impressions that image data can only come from a file. It doesn't need to come from a file. It doesn't matter where it comes from as long as the server sends the data to the HTML page generated by the JSP as a response to the image tag's request.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is not the case, I want to say that, I know , how to display one image from local disk D in jsp, and here the case is ,images retrieved from database, dynamically, so how is it possible, to give image tag each time ,it should be automatic right? the case is user put image and as user request the image stored in database, and then it should be on jsp, this is not the some specific static images..in static case multiple img tag should be fine, by giving name of each image.in my case there are lot images stored dynamically in database as per user request.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you meant different images in a single tag, not multiple images.

Still, the solution is the same. Your img tag references a servlet (not a file), providing enough data on the URL (request or path parameters) so that the servlet knows how to identify which image to fetch from the DB. The servlet then serves the image data as its response (setting appropriate headers).

 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want all images at once from database along with new one in one jsp page, means as user browse new image it saves at database, so I want that new one and all old images also at once in jsp page, so I tried here in jsp
by img tag:

<img src="http://localhost:8017/servletconfiganno/rt1" border="0" />

but I got one image only , how could I fetch all images in jsp page at once which is stored in database?

 
Sheriff
Posts: 28325
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, with an tag you get one image. If you want more than one image you need more than one tag.

If you want all the images in a server-side resource then your JSP needs to generate one tag for each of those images.
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had already pointed that out before -- multiple images on an HTML page require multiple img tags. Remember that regardless of whether you are using JSP or not, your page ends up as an HTML page in the browser and so it must conform to all rules of HTML.

If that's not clear, perhaps reading this article will help.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you give the hint of that code by which , I could fetch all the images from database with only one tag, I can not figure it out by searching on google, I am stuck on it last 15 days, searching on net again and again, if you can tell me, it would be really good for me....
 
Bear Bibeault
Sheriff
Posts: 67752
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sarojni agrwal wrote:can you give the hint of that code by which , I could fetch all the images from database with only one tag


You can't. That's what's been said again and again. If you want more than one image on an HTML page, you need more than one img tag.
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are I used two img tag:


<img src="http://localhost:8017/servletconfiganno/rt1" border="0" />
<img src="http://localhost:8017/servletconfiganno/rt1" border="0" />


but I got two same images on the browser. and one thing, I want to know that, how many tags should I use? (obviously there are no static images, not one or two not 50 images, it is dynamic images stored in database as per user request, when user browse image then it goes in database , then it should display on jsp, so how many tags should I use , in this case, when images are dynamic?)
 
Paul Clapham
Sheriff
Posts: 28325
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course you got the same image twice, the URL is the same in both tags so it would naturally return the same image. If you want it to return different images, you'll need different URLs.

I suppose it still isn't obvious, so let me point out that the URL which requests an image is also going to have to say which image it's requesting. That's usually done by a URL parameter:

<img src="http://localhost:8017/servletconfiganno/rt1?image=2307" border="0" />
 
sarojni agrwal
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is this , image=2307? I can not understand , is this only image name or image id? if id , where should be image id in servlet?
 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sarojni agrwal wrote:what is this , image=2307?


That is a request parameter for a GET request.

You seem to be struggling with some of the basics like parameters and img tags. I think you need to review some of the fundamentals. Try forgetting about jsp and servlets for now and just create an HTML page that displays images the way you want. Then you can work toward a jsp/servlet combination that will generate the html that you want.

Have you read the links that have been provided? Have you looked through our faqs and wikis?
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic