I want to display BLOB image in JSP Using  html tags IMG src=

GoodAfternoon Sir/Madom
I Have got the image from oracle database but want to display BLOB image using <IMG src="" > Html tags in JSP page . If it is possible than please give some ideas or
Send me sample codes for display image.
This code is ok and working no problem here Please send me code How to display using html tag from oracle in JSP page.
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %>
<%@ page import="javax.swing.ImageIcon;" %>
      <%
        out.print("hiiiiiii") ;
            // declare a connection by using Connection interface
            Connection connection = null;
            /* Create string of connection url within specified format with machine
               name, port number and database name. Here machine name id localhost
               and database name is student. */
            String connectionURL = "jdbc:oracle:thin:@localhost:1521:orcl";
            /*declare a resultSet that works as a table resulted by execute a specified
               sql query. */
            ResultSet rs = null;
            // Declare statement.
            PreparedStatement psmnt = null;
              // declare InputStream object to store binary stream of given image.
               InputStream sImage;
            try {
                // Load JDBC driver "com.mysql.jdbc.Driver"
                Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
                    /* Create a connection by using getConnection() method that takes
                    parameters of string type connection url, user name and password to
                    connect to database. */
                connection = DriverManager.getConnection(connectionURL, "scott", "root");
                    /* prepareStatement() is used for create statement object that is
                used for sending sql statements to the specified database. */
                psmnt = connection.prepareStatement("SELECT image FROM img WHERE id = ?");
                psmnt.setString(1, "10");
                rs = psmnt.executeQuery();
                if(rs.next()) {
                      byte[] bytearray = new byte[1048576];
                      int size=0;
                      sImage = rs.getBinaryStream(1);
                    //response.reset();
                      response.setContentType("image/jpeg");
                      while((size=sImage.read(bytearray))!= -1 ){
            response.getOutputStream().write(bytearray,0,size);
            catch(Exception ex){
                    out.println("error :"+ex);
           finally {
                // close all the connections.
                rs.close();
                psmnt.close();
                connection.close();
     %>
     Thanks

I have done exactly that in one of my applications.
I have extracted the image from the database as a byte array, and displayed it using a servlet.
Here is the method in the servlet which does the displaying:
(since I'm writing one byte at a time, it's probably not terribly efficient but it works)
     private void sendImage(byte[] bytes, HttpServletRequest request, HttpServletResponse response) throws IOException {
          ServletOutputStream sout = response.getOutputStream();
          for(int n = 0; n < bytes.length; n++) {
               sout.write(bytes[n]);
          sout.flush();
          sout.close();
     }Then in my JSP, I use this:
<img src="/path-to-servlet/image.jpg"/>
The name of the image to display is in the URL as well as the path to the servlet. The servlet will therefore need to extract the image name from the url and call the database.

Similar Messages

  • Problem with displaying BLOB images on JSP page using a servlet

    hi. I have a big problem with displaying BLOB images using JSP. I have a servlet that connects to the oracle database, gets a BLOB image , reads it, and then displays it using a BinaryStream. The problem is , this works only when i directly call that servlet, that is http://localhost:8080/ImageServlet. It doesn't work when i try to use that servlet to display my image on my JSP page (my JSP page displays only a broken-image icon ) I tried several coding approaches with my servlet (used both Blob and BLOB objects), and they work just fine as long as i display images explicitly using only the servlet.
    Here's what i use : ORACLE 10g XE , Eclipse 3.1.2, Tomcat 5.5.16 , JDK 1.5
    here is one of my image servlet's working versions (the essential part of it) :
                   BLOB blob=null;
              rset=st.executeQuery("SELECT * FROM IMAGES WHERE ID=1");
              while (rset.next())
                   blob=((OracleResultSet)rset).getBLOB(2);
              response.reset();
              response.setContentType("image/jpeg");
              response.addHeader("Content-Disposition","filename=42.jpeg");
                    ServletOutputStream ostr=response.getOutputStream();
                   InputStream istr=blob.getBinaryStream(1L);
                    int size=blob.getBufferSize();
              int len=-1;
                    byte[] buff = new byte[size];
                         while ((len=istr.read( buff ))!=-1 ) {
                   ostr.write(buff,0,len);
             response.flushBuffer();
             ostr.close(); and my JSP page code :
    <img src="/ImageServlet" border="0"  > If you could just tell me what i'm doing wrong here , or if you could show me your own solutions to that problem , i would be very greatful ,cos i'm realy stuck here , and i'm rather pressed for time too. Hope someone can help.

    I turns out that it wasn't that big of a problem after all. All i had to do was to take the above code and place it into another JSP page instead of into a servlet like i did before. Then i just used that page as a source for my IMG tag in my first JSP. It works perfectly well. Why this doesn't work for servlets i still don't know, but it's not a problem form me anymore . Ofcourse if someone knows the answer , go ahead and write. I would still appriceatte it.
    here's the magic tag : <img src="ImageJSP.jsp" border="0"  > enjoy : )

  • Display BLOB Image in a JSP page.

    Hi, Is there any easy way to display a Image in the browser using a JSP and an Oracle BLOB. I would like any code examples that anyone can provide me. I would like as many ways to do this as possible.
    Thanks Brian

    You can do it in 2 ways:
    1. Get the BLOB from the DB and then write it into the local harddisk where the Web Server is located and then give the path in the <IMG SRC> Tag.
    2. In the JSP, when you specify a IMG Tag
    <IMG SRC='FileDisplayServlet?hdImgName=new.gif'>
    This SRC is pointing to a Servlet. The Servlet will read the Query String and then go hit the DB, get the BLOB Content and then convert into a byte array. Now the servlet will change its content type to image or gif. Then it will write the content in the out stream.
    Hope this helps.
    Thanks and regards,
    Pazhanikanthan. P

  • How to display uploaded image in jsp page.

    Hello,
    I am using struts 1.2.9 and and have uploaded image on the server. Now what I want to do display the image in jsp page after clicking on one link in jsp. I have tried many thing to display image in jsp page. But I am getting an error during displaying image in jsp. I have displayed absolute path in servlet. and used InputStream and outputstream to display image in jsp page.
    Can any one help.
    Thanks in advance
    Manveer Singh

    Follow this. This topic is very popular recently on the forum.

  • Displaying BLOB image by using ADF Faces

    Hi all,
    I digged the forum but couldn't find any satisfied answer about displaying BLOB images by using ADF Faces.
    I have insterted POJO object to Oracle database but couldn't find any way to display blob (in java byte [] ) data in POJO.
    I have read the POJO object from database which contains two field; one of them is id field and other is BLOB data which holds GIF or JPG image and I want to display this image another page which contains also other fields / records ...
    thanks for your answers
    regards...
    --baris                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    This thread at Sun : http://forum.java.sun.com/thread.jspa?threadID=513804&messageID=2445090
    talks about two options for creating a graphicImage jsf tag. (img tag)
    1. Make the img tag url refer to a servlet (instead of a static image file)
    2. Embed the image into the tag as inline base64 encoded data.
    2a. Use an <Object> tag with inline data.
    1. Looks a bit complex for a simple problem.
    2 and 2a don't work with some browsers.
    - And I've not yet figured out how to hook into the ADF Faces table-rendering logic to get it to add my image column. My table binds to a collection DataControl, [which in turn retrieves from a findAllItems call on a session facade, which uses my domain model, and wraps up access to a TopLink pesistence layer]. The framework just ignores my byte[] attribute when creating the jsf table from the DataControl. All string, int etc. attributes get represented correctly in the jsf table output.

  • Display BLOB (image) column in (interactive) report

    Hi,
    I have a field called "picture" in my table "details" which is of type BLOB. i also have a field for "MIMETYPE" and "filename"
    i additionally have a "name" and "description" columns which i need to display along with the picture as columns in a report (preferably interactive).
    i have also modified the BLOB display format as per
    http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r31/apex31nf/apex31blob.htm
    what i am missing is the correct query. if possible, i would like to control the size of the picture rendered within the report like say 40*50.
    I have also referred to the thread
    APEX 3.1 Display BLOB Image
    But i don't know how to place the
    dbms_lob.getlength("BLOB_CONTENT") as "BLOB_CONTENT"
    in my query.
    The above also makes the report column as of type "number". is this expected?
    Any help would be much appreciated.
    Regards,
    Ramakrishnan

    You haven't actually said what the problem is?
    >
    I have a field called "picture" in my table "details" which is of type BLOB. i also have a field for "MIMETYPE" and "filename"
    i additionally have a "name" and "description" columns which i need to display along with the picture as columns in a report (preferably interactive).
    i have also modified the BLOB display format as per
    http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r31/apex31nf/apex31blob.htm
    what i am missing is the correct query.
    I have also referred to the thread
    APEX 3.1 Display BLOB Image
    But i don't know how to place the
    dbms_lob.getlength("BLOB_CONTENT") as "BLOB_CONTENT"
    >
    Something like:
    select
              name
            , description
            , dbms_lob.getlength(picture) picture
    from
              details
    if possible, i would like to control the size of the picture rendered within the report like say 40*50.For images close to this size it's easy to do this for declarative BLOB images in interactive reports using CSS. Add a style sheet with:
    .apexir_WORKSHEET_DATA td[headers="PICTURE"] img {
      display: block;
      width: 40px;
      border: 1px solid #999;
      padding: 4px;
      background: #f6f6f6;
    }where the <tt>PICTURE</tt> value in the attribute selector is the table header ID of the image column. Setting only one dimension (in this case the width) scales the image with the correct aspect ratio. (The border, padding and background properties are just eye candy...)
    However, scaling large images in the browser this way is a huge waste of bandwidth and produces poorer quality images than creating proper scaled down versions using image tools. For improved performance and image quality, and where you require image-specific scaling you can use the database ORDImage object to produce thumbnail and preview versions automatically, as described in this blog post.

  • Display the images in excel using jsp

    Hi
    I am unable to display the images in excel using jsp. I can display the data. but cannot display the images. It is simply showing the icon without the image. Is there any way to display the images. Pls give some sample code to display the images in excel.
    Thanks in advance.

    Presumably whoever created the images in that Excel document just put links to somewhere on their hard drive. Those links don't mean anything when you put the document on somebody else's computer, which is what you are doing. At least, that is my guess.
    You could spend some time looking at the Excel file to see how the images were put in there. Or you could ask the person who put the images in there.

  • How to display stored image in jsp  in ie7???

    i am using internet explore7. i have a problem when i am displaying an image in jsp its not properly coming. this image and image is stored in database.
    image is stored in database using "binarystream" .
    i am just simply calling the image path and using the html image display tag.
    <img src="<%=fileIpath%>" but image is not coming properly but this image is showing properly in lower ie version.
    Can anyone help me???

    can anyone reply this question??Appearently no.
    It might be that the question is not interesting enough to attract people.
    Or it might be that the details you provided do no suffice and some important pieces of information are missing. For eample: what are the contents of the variable? If you save the generated page, what do you get?

  • Any other way to display the images in jsp

    Dear All,
    I had a program in get the image in database and display the image in jsp file.
    Generally we are using
    setContenttype(image) and write the binary values in jsp file,
    is there any other way to store the jpeg file in speciefied folder and view the jsp file

    Is there any other way to play the shuffle in a car if it doesn't have an aux facility???
    There is not.
    Or I wondered if you could play it through a smart tv...or do you need an apple tv box???
    Not with the Apple TV, but if the Smart TV has an AUX port, you can connect it that way.
    B-rock

  • Displaying a image on mobile using canvas

    hi all...
    im new to j2ME and i need help on how to display an image on mobile using canvas. I've tried using the following codes.. however when i tried to run on my toolkit, i hit this error:
    Unable to create MIDlet MyCanvasDrawings
    java.lang.IllegalAccessException
         at com.sun.midp.midlet.MIDletState.createMIDlet(+19)
         at com.sun.midp.midlet.Selector.run(+22)
    Im not too sure of wads is the problem with my codes. Here's my codes:
    import javax.microedition.lcdui.*;
    public class MyCanvasDrawings extends Canvas
    private Display display;
    public MyCanvasDrawings(Display display)
         this.display = display;
    public void paint(Graphics g)     
    {//paint
         Image img = Image.createImage("testImage.png");
         g.drawImage(img,getWidth()/2, getHeight(), g.HCENTER|g.VCENTER);
    }//paint     
    }

    import java.io.IOException;
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Font;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;
    public class MyCanvasDrawings extends Canvas
         public MyCanvasDrawings()
         public void paint(Graphics g)
         {//paint
              Image img1 = null;
                   try {
                        img1 = Image.createImage("/ProcureprofitLogo1.jpg");
                   //     img1 = Image.createImage("/welcomeText3.jpg");
                   } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
              g.drawImage(img1,getWidth()/2, 130, g.HCENTER|g.VCENTER);
         }//paint
    But i dont know how to add command

  • JSPs using Custom Tag with Boolean attribute cannot compile

    Hi,
    In Oracle9iAS(9.0.3), a jsp using a tag extension, which has a Boolean attribute, caused the following compile error, although the jsp is valid in other web containers.
    ERROR:
    /opt/oracle/j2ee/home/application-deployments/simple/simple/persistence/_pages/_test.java:56: Method toBoolean(java.lang.Boolean) not found in class _test.
    __jsp_taghandler_1.setExists( OracleJspRuntime.toBooleanObject( toBoolean( b)));
    JSP:
    <%@ page language="java" %>
    <%@ page errorPage="error.jsp" %>
    <%@ taglib prefix="jnpr" uri="/WEB-INF/testtag.tld" %>
    <%
    Boolean b = Boolean.valueOf("true");
    %>
    <jnpr:TestTag exists="<%= b%>"/>
    The boolean value is <%= b %>
    Tag Handler:
    package defaultpak;
    import javax.servlet.jsp.tagext.*;
    import javax.servlet.jsp.*;
    public class TestTag extends TagSupport{
    private Boolean exists = null;
    private java.lang.Boolean getExists() {
    return exists;
    public void setExists(java.lang.Boolean newExists) {
    exists = newExists;
    public int doStartTag() throws JspException {
    return super.doStartTag();
    Is this a known problem? Is there a way to get around this?
    Thanks in advance.
    Fred

    This is a known issue with 903, fixed in coming 904.
    In 903 the workaround is to use primitive type "boolean" instead of Object type "java.lang.Boolean" in user's getter and setter code for the taglib.
    -Prasad

  • HELP!!!!Display blob image using JSP

    Hi,
    I am trying to blob image using JSP but it did not display successfully.
    Can someone help, please?
    below are the codes snippet:
    <td>
    <img src="display_image.jsp?ID=<%=request.getParameter("ID") %>" width="115" border="0">
    </td>
    byte[] image_blob = details.getImageByteArray();
    response.setContentType("image/jpeg");
    //response.setContentType("image/gif");
    //BEGINNING OF SECTION TO DISPLAY IMAGE
    /*OutputStream fos = null;
    fos = response.getOutputStream();
    fos.write(image_blob, 0, image_blob.length);
    fos.flush();
    fos.close();*/
    java.io.FileOutputStream fos1 = new java.io.FileOutputStream("C:\\"+id+".jpg");
    fos1.write(image_blob);
    fos1.close();
    OutputStream o = response.getOutputStream();
    System.out.println("o");
    o.write(image_blob);
    System.out.println(image_blob);
    System.out.println("write image");

    Use Java Image or BufferedImage instead of obscure byte array for image data.
    Here's an example code for a JSP document:
    <%
    String wid = request.getParameter("percent");
    String cost = request.getParameter("suchi");
    response.reset(); //IMPORTANT !
    response.setContentType("image/jpeg");
    // for testing purpose
    if (wid == null) wid = "58";
    if (cost == null) cost = "3400";
    float dleng = Float.parseFloat(wid) * 2.6f;
    RenderedImage rimg = drawGraph(dleng);
    OutputStream os = response.getOutputStream();
    try{
      ImageIO.write(rimg, "jpg", os);
    catch(IOException e){
    os.flush();
    %>
    <%!
    public RenderedImage drawGraph(float barLength){
      final int w = 800;
      final int h = 18;
      final int x = 0;
      final int y = 0;
      BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
      Graphics2D g2 = img.createGraphics();
      Color c = new Color(Integer.parseInt("FF9999", 16));
      g2.setColor(Color.yellow);
      g2.fillRect(x, y, w, h);
      g2.setColor(c);
      g2.fillRect(x, y, (int)barLength, h);
      g2.dispose();
      return img;
    %>

  • Displaying BLOB image in an item

    I have a table with a BLOB column holding an image.
    I can set up a report region with a query on the column like this (the whole sql query is omitted for simplicity, I am just showing relevant column):
    dbms_lob.getlength(a.product_logo)
    and then put a mask on the report column:
    IMAGE:PROJECT:PRODUCT_LOGO:PROJECT_ID::::::inline:Download
    and it works. The report region, when ithe page runs, displays the image.
    My problem is this...
    I am trying to set up a page where I already have an html region serving other purposes. I want to set up an item under that region that would display my image. I create an item of "Display As Text" type.
    I then enter my magic query dbms_lob.getlength(a.product_logo) into the item's "Source value or expression" field, while I set the "Source type" to "SQL Query". In the format mask for the item, I enter the same mask I showed above - "IMAGE:PROJECT:PRODUCT_LOGO:PROJECT_ID::::::inline:Download".
    I run the page and it doesn't work. The item comes back with a number. I am guessing it's the actual getlength value. What else am I missing? Or is it even possible to display an image BLOB through an item and not a report column?
    Thanks
    Boris

    Hi,
    Install demonstrative application and check page 6
    To install demonstrative app go
    Home>Application Builder>Create
    and select Demonstration Application
    Br,Jari

  • How to display BLOB images from the Oracle database within Crystal

    Let's say a have the following table
    IMAGES
    ========
    DOC_ID NUMBER
    DOC_NAME STRING
    DOC_IMAGE BLOB
    The BLOB field can have any type of document: PDF, email, WORD, EXcel, etc. I would like to present the DOC_ID and DOC_NAME and let the user click any of them. Once the user clicks the document stored in the database as BLOB, it is rendered using the default application associated to the extension. For example if the file name is ABC.XLS open MSExcel if the file is abc.pdf open Acrobat.
    I am using Crystal2008 and evaluating Crystal 4.0
    Does this requires programming?
    Thanks!!!

    Hi
    Crystal is a reporting tool and you canu2019t execute any code except free hand SQL.  When you pull any BLOB fields in crystal, it takes as a picture field and if that field contains image only it will display in your report.
    If you have any information other than image, it will not display any info in the report.
    If you want to insert Word , PDF and Excel then you will have to insert as ole object and can manage with location of the files.
    Thanks,
    Sastry

  • Display KM image in JSP

    Hi All,
    I have image in KM folder. I want to display it in JSP as a html image. I am able to
    access the image using below code.
    <%
    try {
         IUser sapUser = componentRequest.getUser();
         com.sapportals.portal.security.usermanagement.IUser ep5User = WPUMFactory.getUserFactory().getEP5User(sapUser);
         IResourceContext resourceContext = new ResourceContext(ep5User);
         String path = "/documents/Images/sample.gif";
         RID imgRID = RID.getRID(path);
         IResource resource = ResourceFactory.getInstance().getResource(imgRID, resourceContext);
         BufferedInputStream bufIn = new BufferedInputStream(resource.getContent().getInputStream());
    byte[] imagebyte = new byte[bufIn.available()];
    bufIn.read(imagebyte);
    catch(Exception e ) { }
    %>
    <img border="0" width="147" height="66" src="">
    Using above code image is stored in a byte array. How to set this as html img tag source.
    Thanks
    Joe

    Hello Sreekanth,
    there are two approaches how to get an KM image into your JSP.
    <b>1) The easy one</b>
    Just put into SRC attribute of your IMG tag next link:
    <b>/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/</b>documents/Images/sample.gif
    Bold part is an access link to KM root. In this case - be aware, the users have to have access rights to given KM object (could be inherited from parent folder).
    <b>2) Through a stream</b>
    In this case you don't have to set access rights for a given resource for all users, you will read the image from Runtime (using ice_service context for example).
    And you can refer to that image as you refer your application. The only thing you need to do - is to write image byte stream to response in your application. Example:
              ByteArrayOutputStream PictureStream = ...;
              if (request.getParameter("Get_Image") != null) {
                        response.setContentType("image/gif");
                        ServletOutputStream sos = response.getOutputStream();
                        response.setHeader("Content-Disposition", "attachment; filename="image.gif"");
                        response.setHeader("Cache-Control", "no-cache");
                        PictureStream.writeTo(sos);
                        sos.close();
                   return;
    And then you address this image stream in your SRC attribute of IMG tag following:
    <u><i><your application url absolute or relative (relative is siggested)>?Get_Image=true</i></u>
    regards,
    mz

Maybe you are looking for

  • Xbox 360 elite + apple 23 inch display???

    so i found the converter from hdmi to dvi but its really expensive around 400+ and would like to find an alternative so if i was to use the dvi to vga for the 23"display then use the vga adapter on the xbox 360 would that possibly do the job needed?

  • RFC gateway trace keeps activating

    Hi experts! We are having a problem in our Live XI environment. The issue is the following: We have an unique communication user and an unique RFC for all the interfaces that uses an RFC channel. The problem is that the gateway trace is being activat

  • Torque

    Hi, I am trying to use Torque to insert a new user to MySQL db but I always get the following exception:" java.sql.SQLException: The url cannot be null" - This is the relevant part from web.xml file: <servlet>   <servlet-name>startserver</servlet-nam

  • Analytics - not counting hits for Images on Portlets

    Hello, We have several portlet with images on them. We also use Analytics 10.3.0. Analytics picks up an image load as a 'hit'. So our top 5 portlets are wrongly showing up as the ones with images because they load with every page refresh - not a user

  • What is function consultant role in technical up grade

    Hi All, Please share your experiences on upgrade project. What is function consultant role in technical up grade. Aditya.