• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Load image fromt disk to servlet

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello friends!

Im being defeating by a servlet I'm trying to load an image from my disk to this servlet. The problem is that when I run it, no image is display. Im not using a jsp or anything else to display the image, I just call the servlet

Here is the code


Thanks a lot for any advide, and sorry for my English
Regards
Diego
 
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try setting the response content type as follows and check --

 
Diego Creador
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Sai!

thanks for the anwser, I tried that but still doesnt work. I debuged the servlet and it looks like the image is copy fine, could it be a problem with the flush?? or should I set the output in somewhere else?


The code with that changes is:


 
Diego Creador
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, sorry for put the code without spaces, is there a way to do it??
 
Sai Hegde
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
use the code blocks to put your code in.... you can always go back and edit your messages
 
Diego Creador
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Done! Now it looks like a decent code.

Could be the problem on the flush? or I should I set the output variable to the response??
 
Sai Hegde
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try doing this...

 
Marshal
Posts: 28193
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
Why do you think an image should be displayed?

I mean, you didn't say you were sending this request from a browser. If you aren't sending the request from a browser then it's the responsibility of whatever receives the response from that servlet to display it.

Or if you are using a browser, you didn't show us the HTML which submits the request. Perhaps the HTML isn't right.
 
Diego Creador
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Appp maybe that could be the problem, here I copy that

My web. xml is this



And my jps file is call image.jsp



 
Sai Hegde
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You said, you were just hitting the servlet... Why do you need that extra jsp for?
 
Diego Creador
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I really dont need it, but I created it to see if that was the problem. My originally idea is just to hit the servlet
 
Sai Hegde
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah, all you need is the servlet.

Map your servlets the correct way in the web.xml...




 
Paul Clapham
Marshal
Posts: 28193
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
Looks like you're confused in the usual way for beginners. You're confused between the code which sends the request and the code which processes the request. (I found that hard to keep straight when I started web programming too.) That JSP you posted doesn't need to be a JSP (like Sai Hegde said). It just needs to be an HTML which sends the request to the servlet.

The HTML part of what you have there looks okay to me. The JSP part, where you declared that the JSP produces a JPEG:



That's the confused part. That JSP doesn't produce an image at all. It produces some HTML which contains an image. It happens that the image that it contains is returned by a servlet, but the HTML doesn't care about that. So when you're testing this, just write a simple piece of HTML which includes the <img> element.
 
Diego Creador
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I modified the web.xml file, but still when I hit the server it cannot display the image. It appear the red X, like the image is not avaible
 
Sai Hegde
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The fact that you see a red cross means that the image is not being found at the location. Please try to put the image in your project root and test your servlet.
 
Diego Creador
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I moved the image to the proyect, created a folder in this path WebContext/imagnes and there drop the image

I change the line thar read the file input stream to this



But It cannot find the file, the method getRealPath gives the rigth location of the jpg but FileInputStream dont find it
 
Diego Creador
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey!
I found out what was the problem, I run this servlet on firefox and works fine. The problem is the IE.

 
Sai Hegde
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I don't think its a browser specific problem. Firefox really doesnt care what kind of image it is once the response content type is set to a image. Can you post the html source for the rendered page in IE.
 
Diego Creador
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont use an html page. I hit the server from the browser usiing http://localhost:8080/ImageExtractor/ImageExtractor
from Firefox works fine, but from IE no image es display (red X like if it missing)
 
Sai Hegde
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Diego,

What was rendered is nothing but an HTML page. Just try running it against IE, right click to View Source and paste it in here.

Thanks,
Sai
 
Diego Creador
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I canĀ“t because the source code option is gray, like it is not avaible. Both in IE and Firefox
 
Sai Hegde
security forum advocate
Posts: 236
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this for a reference and maybe you can point what was it that was incorrect -

https://coderanch.com/how-to/java/ImageServlet
 
Diego Creador
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sai, I found out that the problem could be the jgp flie.

I dragged and dropped on IE and firefox the jpg file , on IE the file couldnt be display on firefox is displayed fine. Perhaps is because this jpg file is a subimage of a larger .tiff file and the IE cant support this?

 
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic