Results 1 to 20 of 24
- 01-22-2012, 11:54 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Geting image from a servlet in a jsp
I am trying to get an image from a servlet. When I try to run the servlet alone, it works and the image is displayed. However, when I try to run it from the jsp with this:
the image is not displayed at all.XML Code:<img src= "ImageServlet" width = "40" height = "50" alt="<%= bean.getItemid() %>"
- 01-23-2012, 01:44 AM #2
Re: Geting image from a servlet in a jsp
What html does the browser get from the JSP?
Is it different from when you run the servlet alone?
- 01-23-2012, 02:03 AM #3
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
Well, just normal html codes as I pasted above. When I run the servlet alone, it works and the image is displayed. I did some tracing and it seems that the servlet is never called from the jsp. But I thought <img src= "ImageServlet" width = "40" height = "50" alt="<%= bean.getItemid() %>" should have called the servlet. If I substitutce src = "ImageServlet" with a local file on my PC, e.g., src ="C:/xyz.jpg", the image is displayed without any issues. What I don't get is why the servlet is not being called? I thought when the code reached img src="ImageServlet" that the servlet should be called automatically.
- 01-23-2012, 11:08 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Geting image from a servlet in a jsp
Well, from what you have posted in the OP, that tag isn't closed.
WHich is why Norm is asking what the HTML (ie what is seen on the client when you view source) is in both instances.
Because it is pretty certain to be different.
- 01-23-2012, 02:34 PM #5
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
OK, after clicking on page source, this is what is seen by the browse:
and so on until the loop loops through all the items, which are 12, each time incrementing the image if (the alt field) by 1.XML Code:<img src= "ImageServlet" width = "40" height = "50" alt="1"/>
and as you can see the tag is closed. And as I said, if I replace it with, e.g.,it works without any problems.XML Code:<img src= "c:myimagefile" width = "40" height = "50" alt="1"/>
Last edited by Dreaming; 01-23-2012 at 02:40 PM.
- 01-23-2012, 05:02 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Geting image from a servlet in a jsp
You said "when I run the servlet alone it works"...so which of the above <img> tags works against the servlet?
- 01-23-2012, 05:08 PM #7
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
The one where I used a local image file works; the one when I use the servlet as image source, does not work.
- 01-23-2012, 05:57 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: Geting image from a servlet in a jsp
Right, so:
"When I try to run the servlet alone, it works and the image is displayed."
isn't actually the case.
When you use <your website>/ImageServlet in your browser what happens?
- 01-23-2012, 08:01 PM #9
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
When I use <mywebsite>/ImageServlet the image is displayed.
- 01-23-2012, 09:36 PM #10
Member
- Join Date
- Jan 2012
- Location
- Panamá
- Posts
- 41
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
which is the location of the jsp?.
TryPHP Code:<img src= "/ImageServlet" width = height = "50" alt="1"/> "40"/>
- 01-23-2012, 10:06 PM #11
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
I don't know what you mean by your question of "which is the location of the jsp?" but I tried your code and still the same.
- 01-23-2012, 10:14 PM #12
Member
- Join Date
- Jan 2012
- Location
- Panamá
- Posts
- 41
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
have reviewed the web.xml, that contains <servlet-mapping>
and <servlet> to ImageServlet
If you can put here, as written in the web.xml
- 01-23-2012, 10:17 PM #13
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
I didn't understand what you meant but I guess you meant that I post here the web.xml file? This is the part for that servlet
XML Code:<servlet> <servlet-name>ImageServlet</servlet-name> <servlet-class>servlet.ImageServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>ImageServlet</servlet-name> <url-pattern>/ImageServlet</url-pattern> </servlet-mapping> <servlet>
- 01-23-2012, 10:23 PM #14
Member
- Join Date
- Jan 2012
- Location
- Panamá
- Posts
- 41
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
The url is with bar
PHP Code:<url-pattern>/ImageServlet</url-pattern>
PHP Code:<img src="/ImageServlet">
- 01-23-2012, 10:26 PM #15
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
I am also seeing some strange behaviour, probably the problem lies with caching. As I said before, when I run the servlet on its own, the image is displayed. Now if after running the servlet, I run the jsp, it displays the last image that was displayed when I ran the servlet. So it seems the images are being cached somewhere and instead of looping through all the images (have a for-loop in the jsp), it just basically does nothing and only tries to fetch the last image, or something. Don't know, it is confusing. If there is a way to disable caching, can someone tell me, then will see if that makes difference.
- 01-23-2012, 10:28 PM #16
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
- 01-23-2012, 10:34 PM #17
Member
- Join Date
- Jan 2012
- Location
- Panamá
- Posts
- 41
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
puts this:
<head>
<meta http-equiv="Pragma" content="no-cache">
</head>
- 01-23-2012, 10:34 PM #18
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
Re: Geting image from a servlet in a jsp
I don't know. I tried reproducing the problem where the last image is displayed but could not, it just seems to happen randomly. Something is amiss somewhere.
- 01-23-2012, 10:35 PM #19
Member
- Join Date
- Oct 2011
- Posts
- 49
- Rep Power
- 0
- 01-23-2012, 10:37 PM #20
Member
- Join Date
- Jan 2012
- Location
- Panamá
- Posts
- 41
- Rep Power
- 0
Similar Threads
-
Image Upload use Only servlet and jsp
By RaviGupta0709 in forum Java ServletReplies: 2Last Post: 05-31-2011, 06:49 AM -
How to upload image in jsp/servlet
By ibhaviik in forum Java ServletReplies: 11Last Post: 11-16-2010, 11:32 AM -
geting value from text
By Mekonom in forum New To JavaReplies: 10Last Post: 12-15-2009, 12:22 AM -
sending image file from JSP to Servlet
By ravian in forum Advanced JavaReplies: 2Last Post: 01-10-2008, 02:34 PM -
problems when loading an image in servlet
By oregon in forum Java ServletReplies: 1Last Post: 08-05-2007, 06:02 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks