This discussion is archived
4 Replies Latest reply: Jan 29, 2013 2:03 AM by Frank Nimphius RSS

Image not displaying  using servlet

810494 Newbie
Currently Being Moderated
Hi all,

I am trying to display image on my jspx page.
I actually get the image from a webservice call which returns the image in base64 format
like a string.
So to simplify the process I have captured the webservice response and am hard coding the value it returns in
image servlet.
Below is what am doing in doGet of servlet:

String str = ""[ hardcoding response from webservice]
byte[] bytes = str.getBytes();
InputStream in = new ByteArrayInputStream(bytes);
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
os.write(buf);
}
Also I have set up the web.xml and the source tag am using in the jspx for image is :
/imageservlet1?id=#{bindings.pic.inputValue} where pic is a column of VO of type String.
But am not passing any parameter to the servlet as I am directly hardcoding the value.

When I run the app, servlet is called but the image does not show up on the page.

Can you please advise where its going wrong..

Regards,
Malathy.
  • 1. Re: Image not displaying  using servlet
    Timo Hahn Oracle ACE
    Currently Being Moderated
    Malathy, which jdev version do you use?

    You are aware of the fact that a string isn't the right type to hold binary data. The first 0 byte you put into the string will end it. when you read or print the content of the string everything after the first 0 byte is lost.

    Next thing to check are the headers you have set for the response. Which mime type have you set?
    Have you written the data from hte WS into a file and tried to show hte image using any image software you have access to?

    Timo
  • 2. Re: Image not displaying  using servlet
    810494 Newbie
    Currently Being Moderated
    Timo,

    The Jdev version I use is 11.1.1.7.0.
    Yeah, what you told is right, String is not the correct format..so I am converting it into bytes and then passing to the input stream.
    I am not sure if this is sufficient.
    Also I have tried through an online tool to decode the base64data response I got from WS and it did show the image nicely.So there seems to be
    no problem with the WS response.


    Regards,
    Malathy
  • 3. Re: Image not displaying  using servlet
    810494 Newbie
    Currently Being Moderated
    Timo,

    I have used the below code and it worked.

    byte[] bytes = str.getBytes();
    BASE64Decoder decoder = new BASE64Decoder();
    byte[] decodedBytes = decoder.decodeBuffer(str);
    InputStream in = new ByteArrayInputStream(decodedBytes);


    Thanks,
    Malathy.
  • 4. Re: Image not displaying  using servlet
    Frank Nimphius Employee ACE
    Currently Being Moderated
    to user8028603 ,

    when working with Oracle internal (non production) builds its always worth testing if a problem reproduces in a public build before posing to a public forum. In your case it seems that build versions don't matter but in many cases internal builds are unstable and produce issues that are not reproducible in external (public) builds that people on this forum have access to

    Frank

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points