How to render an image (byte array) in a JSP

I don't know how to solve this:
I have a bean 'Details' with a property 'photo'
This bean is read in a servlet and put into session scope like this:
PhotoDetails Details = getPhotoDetail(some_id);
HttpSession session = request.getSession();
session.setAttribute("photo", Details);
Then I forward to a JSP, where properties of the bean are listed:
<bean:write scope="session" name="photo" property="photo_description" />
Till now, it works fine,
but now I want to display the 'photo' property. This fails ....
I try to do this:
<html:img src="/servlets/PhotoDisplayer" />
I use an html:img tag and I call a servlet which should stream the photo
to the JSP page. I hope the servlet pick the photo attribute from the
session.
Here is the PhotoDisplayer Class:
public class PhotoDisplayer extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PhotoDetails photoDetail = (PhotoDetail)
request.getSession(true).getAttribute("photo");
byte[] photo = photoDetail.getPhoto();
response.setContentType("image/jpg");
OutputStream os = response.getOutputStream();
BufferedOutputStream bos = new BufferedOutputStream(os);
bos.write(photo, 0, photo.length);
bos.close();
But nothin happens, I don't see a picture/photo on the JSP page.
If someone can help with this, I will appreciate that.
kind regards,
Harryvanrijn

Karthik:
It should not be difficult to debug what is exactly the cause of your problem.
Firstly, use your servlet to display an existing .jpeg or .jpg file that you know it is good.
If it is ok, then the problem lies in getting the image from the blob. To confirm it, you can try saving the image from the blob into a .jpeg file and viewing it through any graphic viewer, like the Windows accessory "paint".
If it is not ok, then the problem lies in your servlet or browser. Make an html that contains a link to your image. Save it to the disk as a .jpg file through the browser. Is it the same as the file saved from blob directly? View the file through a graphic viewer.
Well, that is the idea. Just try various variations and locate the exact place where it goes wrong in your situation. Please tell me if this helps or not.

Similar Messages

  • How to split the blob byte array and insert in oracle

    how to split the blob byte array and insert in oracle
    I am having a string which is of more than lenght 4000 so i am using BLOB datatype as input to get the string.
    need to split the blob in oracle and store in the different column
    The string is of bytearray i need to strore it in each column based on the byte array.

    this will be my input i need to split the above and store it in different columns in a table.
    for spliting say
    Column1 -1 byte
    Column2-3 byte
    Column3-5 byte
    ColumnN-5 byte
    Table will have corresponding data type
    Column1 - number(10,2)
    Column2 - Float
    Column3 - Float
    ColumnN-Float
    here Column2 datatype is float but it will always have 3 byte information.
    where as Column3 datatype is also float but it will always have 5 byte information.
    Say N is Column 120

  • Image Byte Array

    How do we get byte array of an image(immutable/mutable) object.I want to save it in RMS tht is why i need to get the image in byte array form.
    I want to send mutable and immutable images through HTTP.Is it possible to do so ??Please Help.
    Thnks in advance.

    Why don't you just try in stead of asking questions. I'm not here to hold you hand on every step. The api docs should provide you with more than enough information to help you on your way. You'll just need to reed that information very well.

  • How do I get a byte array from an object passed into the JNI?

    This is what my java code looks like:
    public class streamedData
    protected byte[] m_value = null;
    public byte[] getByteArray ()
    return m_value;
    /* code not pertaining to this question snipped. */
    jclass streamedDataClass = env->GetObjectClass(jstreamedData);
    // Get methodIDs for the various NPKI_Extension methods
    value = env->GetMethodID(streamedDataClass, "getByteArray", "()[B");
    lstreamedData->value = (unsigned char *)malloc (lstreamedData->length);
    if (lstreamedData->value == NULL)
    return INSUFFICIENT_MEMORY;
    memset (lstreamedData->value, 0, lstreamedData->length);
    memcpy (lstreamedData->value, env->CallByteMethodA(streamedDataClass, value, NULL), lstreamedData->length);
    This is not working.
    My question is, how do I get a copy of or read m_value in the JNI layer? Do I have to make the byte array public and access it as a field ID?
    Any help would be appreciated. Why oh why can't there be a CallByteArrayMethod????

    My question is, how do I get a copy of or read m_value in the JNI layer? Do I have to make the byte array public and access it as a field ID?
    You can retrieve a handle to the byte array, through a method call, as you're doing now, or by directly accessing it through GetFieldID.
    In the case of the method call, you'll want to do:jmethodID getByteArrayMethod = env->GetMethodID(streamedDataClass, "getByteArray", "()[B");
    jbyteArray byteArray = static_cast<jbyteArray>( env->CallObjectMethod( jstreamedData, getByteArrayMethod ) );In the case of field access, you can do:jfieldID m_valueFieldID = env->GetFieldID( streamedDataClass, "m_value", "[B" );
    jbyteArray byteArray = static_cast<jbyteArray>( env->GetObjectField( jstreamedData, m_valueFieldID ) );Once you have byteArray, you need to access it using the array operations:lstreamedData->value = env->GetByteArrayElements( byteArray, 0 );
    // Do what you want to do, then release the array
    env->ReleaseByteArrayElements( byteArray, lstreamedData->value, 0 );As always, Jace, http://jace.reyelts.com/jace, makes this easier. For example,void printByteArray( jobject jstreamedData ) {
      streamedData data( jstreamedData );
      JArray<JByte> byteArray = streamedData.m_value();
      for ( int i = 0; i < byteArray.length(); ++i ) {
        cout << byteArray[ i ];
    }God bless,
    -Toby Reyelts

  • How to make use of byte array to perform credit and debit in Wallet Applet

    Hi,
    Can anyone please explain me how to use the concept of byte arrays.. to perform credit and debit operations of a 6byte amount. Say for example.. the amount contains 3 bytes whole number, 1 byte decimal dot and 2 bytes fractional part.
    It would be helpful if anyone could post a code snippet.. that way i can undersatnd easily.
    Thanks in Advance
    Nara

    Hello
    as explained in the other topic, remember your high school years and how you leart to add numbers.
    then, reproduce these algorithms for base-256 numbers.
    fractional? just google about fixed point math and floating point math. The first one is easier, as they are managed as integers.
    example, you want to store 1,42€. Then you decide the real number to deal with is N*100, and you store 142. You get 2 decimal places of precision.
    in the computer world it's easier to store n*256 as it's just a byte shift.
    then the addition operations are the same, and you just interpret the values as fractional numbers.
    regards
    sebastien

  • Image Byte Array - Hex?

    Hi all,
    I'm trying to read in an image and get an int / hex array out of it. Basically, I want to get an array that would look like what you see if you open an image in a hex editor. I have no problems getting a byte array using..
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    ImageIO.write( bufferedImage, "jpg", stream );
    bytes = stream.toByteArray();
    But, it's weird, it's not really what I want. The result is not the same as what I see if I drop the same image into a hex editor and look at the bytes. Not sure if I need to convert the bytes to hex or what. Any help would be much appreciated.

    hmm.. can you explain a bit?.. let's say I do...
    BufferedImage srcImage = ImageIO.read( new File( pathIn ));
    ByteArrayOutputStream streamIn = new ByteArrayOutputStream();
    ImageIO.write( srcImage , "jpg", streamIn );
    byte[] bytes = stream.toByteArray();
    ByteArrayInputStream streamOut = new ByteArrayInputStream( bytes );
    BufferedImage writeImage = ImageIO.read( streamOut );
    ImageIO.write( writeImage, "jpg", new File( pathOut ));Looks a little odd out of context, I know. But, basically, the resulting image is different than the original image. I assume, maybe, there is some sort of compression going on. But i don't really know. Should I be decoding / encoding in specific formats to get the resulting image to be /exactly/ the same as the source?
    thanks

  • How dose BigInteger translate a byte array

    I dont know if this is obvious or not, but where can i find the algorithm used by BigInteger for translating byte/array of bytes into a number?

    I dont know how, but you can have look in BigInteger source file.

  • How to publish self-composed bytes array as video ?

    So far I only find the way to publish camera video as stream: attachCamera()
    Is it possible to publish self-composed bytes array as video ?

    i don't believe there's a way to inject bytes into a publishing NetStream and have it encapsulated as though it was a video message.
    however, you could do NetStream.send("onVideoBytes", myBytes) at the publisher, and receiver(s) could, in their onVideoBytes() handler, use NetStream.appendBytes() on a different NetStream (connected to a video component) to display your generated video data.
    using appendBytes() properly for this purpose is an exercise for the reader. 
    -mike

  • How do i clear a byte array?

    Hi. I'm reading a different chunk of data each time and therefore need to clear the byte array before I go to the next chunk. I've seen
    other ways through a buffer but that is too complicated for me to understand. Can u please tell me if there is a simple method in the API to clear it?
    Thank you!!

    well i thought it was, but i'm using the matcher class to read the data and storing it in a byte array of size 512 and it seems that when i convert it into a string, the previous data is still there if i read something less than 512
    Edited by: angel32013 on Sep 16, 2008 1:08 PM

  • How do you display images relative to a Portlet JSP page?

    For Welblogic Portal 7.0, I want to display a simple image (.gif) on a JSP page.
    The problem is that I need to use a 'hard coded' url to the image such as the following:
    <img src="portlets/test/images/test.gif" border="0" alt="Test 1">
    - OR -
    <img src="<webflow:createResourceURL resource="/portlets/test/images/test.gif" />"
    border="0" alt="Test 2">
    This makes the portlet less portable.
    My goal is to display an image relative to the current JSP Portlet page (in the test
    directory).
    Does anyone know how to accomplish this?
    In WL Portal 4.0 I used:
    <img src="<%=fixupRelativeURL(pathFromRequest(request) + "images/test.gif", request)%>"
    width=24 height=22 border=0 alt="test">
    This does not work anymore as fixupRelativeURL does not seem to exist in the 7.0
    API.
    Your help would be greatly appreciated!
    Thanks,
    Matt

    Exactly what I was looking for!
    Thank you Subbu.
    Subbu Allamaraju <subbuATBeaDOTCom> wrote:
    Matt,
    There is an indirect way to achieve this.
    (a) In your portlet JSP, get the PortletState. There is an example in
    /framework/portlet.jsp.
    (b) Get the content URL for this portlet by calling
    portletState.getUrl(Portlet.URL_CONTENT).
    Depending on where your image is (with respect to the content URL), you
    can construct a new URL to the image. For example if your content is at
    at /portlets/myportlet/foo.jsp and your image is in at
    /portlets/myportlet/images/myimage.gif, you can reconctruct the latter
    from the first one.
    Once you do this, prepend the constructed URL with the web app context
    root (request.getContextPath()).
    Hope this helps.
    Subbu
    matt wrote:
    For Welblogic Portal 7.0, I want to display a simple image (.gif) on aJSP page.
    The problem is that I need to use a 'hard coded' url to the image suchas the following:
    <img src="portlets/test/images/test.gif" border="0" alt="Test 1">
    - OR -
    <img src="<webflow:createResourceURL resource="/portlets/test/images/test.gif"/>"
    border="0" alt="Test 2">
    This makes the portlet less portable.
    My goal is to display an image relative to the current JSP Portlet page(in the test
    directory).
    Does anyone know how to accomplish this?
    In WL Portal 4.0 I used:
    <img src="<%=fixupRelativeURL(pathFromRequest(request) + "images/test.gif",request)%>"
    width=24 height=22 border=0 alt="test">
    This does not work anymore as fixupRelativeURL does not seem to existin the 7.0
    API.
    Your help would be greatly appreciated!
    Thanks,
    Matt

  • NetBeans MobilityPack 5 BUG?? how can I send a byte array?

    I�ve created a WebApp and a Simple servlet with one public method.
    public byte[] getStr(byte[] b) {       
    String s = "A string";
    return s.getBytes();
    Then I've used "Mobile To Web App" wizard to generate stubs to that getStr method. And when I�ve tried to call that getStr method:
    byte[] aByte = "st".getBytes();
    byte[] b = client.getStr(aByte);
    I've got an error at Server in Utility.java in generated ReadArray method.
    * Reads an array from the given data source and returns it.
    *@param source The source from which the data is extracted.
    *@return The array from the data source
    *@exception IOException If an error occured while reading the data.
    public static Object readArray(DataInput in) throws IOException {
    short type = in.readShort();
    int length = in.readInt();
    if (length == -1) {
    return null;
    } else {
    switch (type) {
    case BYTE_TYPE: {
    byte[] data = new byte[length];
    in.readFully(data);
    return data;
    default: {
    throw new IllegalArgumentException("Unsupported return type (" + type + ")");
    At this line "in.readFully(data);" I�ve got an EOFException.
    The the aByte = "st".getBytes(); was 2bytes long and at the server "int length = in.readInt();" it was 363273. Why?
    All code was generated by NetBeans Mobility pack 5 it's not mine so its a bug?
    How can I fix this?

    I found that bug. I've described it here
    http://www.netbeans.org/issues/show_bug.cgi?id=74109
    There's a solution how to fix the generated code.

  • How to render cids images

    I have an email read with CFPOP, with 2 embeded images.
    I did a cfdump of the cids :
    I can see the 2 images names and cids,
    But is it possible to render at least one image in the webmail via the CFPOP ?
    Thanks for help.

    Here is part of the solution : Working when cids files are loaded.
    The image src is like : cid:[email protected]
    <cfloop collection="#cids#" item="x">
          <cfset i=#findnocase("<",cids[x])#>
          <cfif i is not 0>
           <cfset j = findnocase(">",cids[x],i)>
           <cfif j is not 0>
            <cfset cid1=removechars(cids[x],j,len(cids[x]))>
            <cfset cid1=removechars(cid1,1,i)>
            <cfset cid1="cid:" & cid1>
            <cfset at_file=http_start & "/attach_Rec/" & x>     <!--- full path of the downloaded file --->
            <cfset tbody=replacenocase(body,cid1,at_file)>
           </cfif>
          </cfif>
       </cfloop>
    There is may be an other solution in new tags or CF functions ?
    And when the CID file is not downloaded, this cannot not work.
    The CID code should correspond to an Internet adress (http://xxxxxxx) but I do not know how to understand this CID.
    The src image is like :
    cid:[email protected]

  • How to send the image bytes(which is taken from webcam) from flex(4.6 version) to dotnet

    In my project we are using adobe flash builder 4.6 as a client-side scripting,visual studio as a mediator(for connecting the oracle database).In this, in flex 4.6 we are capturing images from webcam that's working fine, after capturing the image we need to save this captured image in oracle database so in order to save we need to pass this image from flex to dot-net(visual studio) so i need a help on how to approach to done this(passing the image from flex to dot-net) if any one knows please help me i will be very thankful to them

    finally i got the solution fot this,i tried using yhis link it work's for me
    http://stackoverflow.com/questions/5702239/how-to-pass-image-from-a-flex-application-to-a- asp-net-c-sharp-web-service

  • I would like to know how i can save an byte array to a mat file format (matlab file format '*.mat') within to use the matlab API

    So, I search the binary matlab file format('*.mat').

    Title:
    Moving Data Between MATLAB® and LabVIEW
    Problem: 
    How can I share data between LabVIEW and the MATLAB environment?
    Solution: 
    MATLAB users can move data between the
    MATLAB environment and LabVIEW, you have several options. Prior to
    LabVIEW 5.1, the only way to transfer data between these two
    environments was to use the Save and Load functions. Those are discussed herein.
    Beginning
    in LabVIEW 8.0, MathScipt was introduced. MathScript is an integrated
    part of LabVIEW that you can use to combine intuitive graphical
    dataflow programming with math-oriented textual programming. See the
    attached links below for more information on MathScript.
    Beginning
    in LabVIEW 5.1, the MATLAB script node was introduced into the LabVIEW
    programming environment. The MATLAB script node makes ActiveX calls to
    the MATLAB software from within LabVIEW. This requires that both MATLAB
    be installed on the same machine and that a valid license is obtained.
    More information on the MATLAB script node can be found in the attached
    KB's.
    For all versions of LabVIEW, this data transfer can be
    performed by saving the data in a file using the MATLAB software and
    reading it directly from LabVIEW, or vice versa. In the MATLAB
    environment, the command "save" allows you to save the data in
    binary format (*.mat) or ASCII format. You also have an option of
    saving it in ASCII format using a tab delimiter between data points and
    the command "load" allows you to read in the data.
    ASCII Format
    Complete the following steps to import or export data between LabVIEW and the MATLAB environment using an ASCII file format.
    From the MATLAB environment to LabVIEW
    To save a vector or a matrix X in tab-delimited ASCII format, enter the following in the command window or m-script file in the MATLAB environment:
    >>SAVE filename X -ascii -double -tabs
    This creates a file named filename containing data X in tab-delimited ASCII format.
    Import the file into LabVIEW using the Read From Spreadsheet File VI located on the Functions»File I/O palette.
    From LabVIEW to the MATLAB environment
    To export a matrix X from LabVIEW to the MATLAB environment, first save the data in ASCII format in LabVIEW using the Write To Spreadsheet File VI on the Functions » File I/O palette.
    Enter the following in the command window of the MATLAB environment, or in the m-script file:
    >> LOAD filename
    This reads the data into the MATLAB environment.
    Binary Format
    Complete the following steps to import or export data between LabVIEW and the MATLAB environment.
    From the MATLAB environment to LabVIEW
    As mentioned above, LabVIEW does not save multiple variables to one
    data with extra manipulation, and will not be discussed here.
    Therefore, the only way of sending the data from the MATLAB environment
    to LabVIEW without tampering with the MAT binary file structure is
    using the ASCII format. Also, please bear in mind that you need to have
    one file for one variable.
    From LabVIEW to the MATLAB environment
    Because
    the MATLAB software saves data in its own binary format, the "MAT"
    file, binary LabVIEW data must be converted to this format prior to
    transferring the data. The attached examples can be used to save
    LabVIEW data in the MATLAB software format. The convenience of the .MAT
    file format is that more than one variable can be saved in the same
    file. The example shows saving seven variables to .MAT format; the
    example can be modified for any number of variables.
    Once this data is saved from LabVIEW, it can be read into the MATLAB environment, using the following command:
    >>LOAD filename
    The Who
    command can then be used to display all the seven variable names, and
    you can display the content of them by entering the variable names at
    the command prompt as usual.
    MATLAB® is a
    registered trademark of The MathWorks, Inc. Other product and company
    names listed are trademarks and trade names of their respective
    companies.
    | Michael K | Project Manager | LabVIEW R&D | National Instruments |

  • How to create thumbnail images on the fly from JSP or servlet?

    Hi all,
    Iam new to this forum. I need a solution for the problem iam facing in building my site. Ihave groups and briefcase section in my site. I allow users to upload files and pictures.
    When they upload pictures i need to create thumbnail for them on the fly.
    Is there any taglibs or java source to do this from JSP or servlets.
    It would be very greatful if i can get an early answer.
    Please let me know if there is any other forum where i can get better answer, if not here?
    thnx.

    Here is how you can create dynamic images:
    http://developer.java.sun.com/developer/JDCTechTips/2001/tt0821.html#tip2
    However, if you want to create gifs/jpegs and save them to the disk it depends from where you want to create the images. It is different if you are creating from another image or just drawing one from scratch etc.. But in the end you will probably need to use one of the imageencoder classes and write the result to the disk with the file io classes.

Maybe you are looking for