Displaying a image in a JSP

I want to display a jpg image in a jsp I have added the line
<img src = “img/backImage.jpg”>
Into the body of my jsp page.
I have placed the backImage.jpg into a folder called img which is in the WEB-INF folder.
When I run the application the picture does not display.
Do I have to configure the application to find the folder?
Full code is below.
Thanks
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Pageeee</title>
    </head>
    <body>
        <img src="img\backImage.jpg" alt="Angry face" />
    </body>
</html>

The WEB-INF folder is not the root of your web application - the parent directory is. Move the img folder up one level to be a sibling of WEB-INF.
<img src="img\backImage.jpg" alt="Angry face" />and the web isn't Windows - your backslash won't work well.

Similar Messages

  • 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

  • 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 : )

  • Displaying Image on th JSP page

    Hello All,
    I am using following code to display the image on the JSP page in my iView
    <% String PublicURL = componentRequest.getPublicResourcePath()+ "/images/Image1.gif"  ; %>
    <hbj:image id="Logo" width="70" height="35" 
                               src="<%= PublicURL %>"
                               alt= "picture Ericsson.gif" />
    Am I missing anything. I am still not able to display the image.
    Regards,
    Sanjeev

    change
    componentRequest.getPublicResourcePath()
    to
    componentRequest.getWebResourcePath()

  • Display 'no photo' in a JSP when photo is not present in DB

    Hi All
    I have stored an image in database uploded from the JSP. The DB has a BLOB column for the image. I have to display a single record at a time. I am able to display the image at the JSP also using <img> tag and specifying the JSP name fetching the image as the src attribute of the <img> tag.
    My doubt is, if the image is not uploded for that record how to display some error message(like 'No Photo Uploaded') on the JSP page? and how can we also suppy a link to upload the photo, if already not uploaded. Since I am displaying the image as a part of another JSP having an <img> tag to display the image.
    Could someone please help me??
    Thanks & Regards
    Inder Jeet Singh

    Use an attribute to determine whether the record has a photo uploaded or not. Check the attribute value in the JSP and write the scriplet accordingly.
    Example:
    <% if (request.getAttribute("Photo") == null){
    %> <TR>
         <TD align="center" colspan="2">
              <CENTER><IMG src="Photo Source here" height="250" width="375" align="middle">
              </CENTER>
         </TD>
    </TR>
    <% }else{
    %>          
    <TR>
         <TD align="right"><FONT size="1">Building Photo:</FONT></TD>
         <TD><INPUT type="submit" name="" value="Associate Photo" onclick="return buildingPhoto()"></TD>
    </TR>
    <% } %>     
    In the above example I set the Photo attribute to null if there exists a photo.
    Message was edited by:
    srpunreddy

  • Display Image in another jsp

    hello,
    I am facing a design issue of so as to how to go about displaying an image which i am retrieving from database.
    I have a SubmitDoc.jsp which takes as input the doc id which i need to display looks like :
    *SubmitDoc.jsp*
    <FORM METHOD=POST ACTION="Retrieval">
    Enter Document ID to Retrieve: <INPUT TYPE=TEXT NAME=DOCID SIZE=20/><BR>
    <P><INPUT TYPE=SUBMIT></P>
    </FORM>I have my Retrieval servlet which access the DB and gets the binary stream for the image data based on DOCID.
    Now i try to forward result to a different jsp in order to display the binary data from the servlet.
    something like this :
    InputStream readImg = rs.getBinaryStream("DOCUMENT");
    response.setContentType("image/jpg");
    request.setAttribute("ImageData", readImg);
    // response.getOutputStream().write(rb,0,len);
    RequestDispatcher rd = request.getRequestDispatcher("DisplayDoc.jsp");
    rd.forward( request, response );What code should i put in DisplayDoc.jsp to show the image there.
    Any ideas how do i go about ?
    Thanks,

    What code should i put in DisplayDoc.jsp to show the image there.The same code you put in any html page to show an image:
    <img src="urlToDownloadImageFrom"/>In effect you have two requests.
    One for the JSP page, and then another for the image.
    So often what you find is the tag on your page needs to pass the id as well
    <img src="/ImageServlet?docId=abc123"/>

  • 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.

  • Display multiple Images from a DB on a JSP Page!

    Hi all, please give me your solution, thanks. I have many images, stored in Oracle database (BLOB), How to display all of them (images) on a JSP page? I have a working solution that only shows one image based on the specific image-name passed. But if no image found in the Database with that image-name then I want to show all the images at once on a JSP page. Can someone help please. Follwing are the code snippets:
    Here is the JSP page that calls the servlet to show the images:
    <%@ page contentType="text/html;charset=windows-1252"%>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <title>untitled</title>
      </head>
      <body valign=center>
          <table>
            <tr>
                <td>
                    <img src="/test-testimgs-context-root/servlet/test1.images.servlet.GetImage">
                </td>
            </tr>
          </table>
      </body>
    </html>
    Here is the code that resides in the service method of GetImage servlet:
    public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
        OutputStream stream = response.getOutputStream(); 
        Blob imgBlob = null;
        ResultSet rs = null;
        byte[] imbBytesAry = null;
        try
            ImageTest imgtest = new ImageTest();
            rs = imgtest.get("img1.tif");
            if(rs != null)
                while(rs.next())
                    imgBlob = rs.getBlob(1);
                    int len = new Integer( new Long( imgBlob.length()).toString() ).intValue();
                    imbBytesAry = imgBlob.getBytes(1,len);
                    if (imbBytesAry.length == 0 || imbBytesAry == null)
                        noImageFound(request, response); 
                    else
                        stream.write(imbBytesAry);
            else
                noImageFound(request, response);
        catch (Exception e)
            noImageFound(request, response);
    Here is the code that resides in the get method of ImageTest class:
    public ResultSet get(String fileName) throws DatabaseConnectionException, SQLException, Exception
    Connection connection=null;
    ResultSet rs = null;
    ResultSet rs1 = null;
    Blob imgBlob = null;
    try
        connection = new ConnectionProvider().getCConnection() ;
        connection.setAutoCommit(false);
        Statement stmt = connection.createStatement();
        String sql = "SELECT IMG FROM IMAGE_TABLE WHERE IMAGE_NAME = ? "; 
        PreparedStatement pstmt = connection.prepareStatement(sql);
        pstmt.setString(1,fileName);
        rs = pstmt.executeQuery();
        boolean flag = rs.next();
        if(flag)
            rs.beforeFirst();
        else
            sql = "SELECT IMG FROM IMAGE_TABLE"; 
            rs1 = stmt.executeQuery(sql);
            boolean flag_all = rs1.next();
            if(flag_all)
                rs1.beforeFirst();
            else
                rs1 = null;
        return rs;
    }As you see in the JSP page I am calling GetImage servlet, whose service method does all the processing i.e. calls ImageTest get method that queries the database and returns the result. Eventually what I would like is to pass the filename along with other parameters from JSP page and the servlet returns the images based on that. Currently I have just hard coded a value for testing puposes. Any help is appreciated.
    Thanks

    Hi all, please give me your solution, thanks. I have many images, stored in Oracle database (BLOB), How to display all of them (images) on a JSP page? I have a working solution that only shows one image based on the specific image-name passed. But if no image found in the Database with that image-name then I want to show all the images at once on a JSP page. Can someone help please.
    this is the code
    <form name="a" action="" method="post">
    <%
    rs1 = st1.executeQuery(select1);
    rs1.next();
    while(rs1.next())
    %>
    <table>
    <tr><td>
    <%
    Blob objBlob[] = new Blob[rs1.getMetaData().getColumnCount()];
         for (int i = 0; i <= rs1.getMetaData().getColumnCount(); i++)
               objBlob[i] = ((OracleResultSet)rs1).getBLOB(1);
              InputStream is = objBlob.getBinaryStream();
    byte[] bytearray = new byte[4096];
    int size=0;
    response.reset();
    response.setContentType("image/jpeg");
    response.addHeader("Content-Disposition","filename=getimage.jpeg");
    while((size=is.read(bytearray))!= -1 )
    response.getOutputStream().write(bytearray,0,size);
    response.flushBuffer();
    is.close();
    out.println("hhhhhhh");
    %>
    </table>
    <%
    rs1.close();
    //con.close();
    %>
    </form>

  • 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.

  • 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.

  • Proble displaying images dynamically in jsp

    Hi, I am new here. I have to display the images dynamically reading from a database. I have no problem displaying images. When i try to reduce the width in img tag then it is slowly rendering it. How to overcome this.
    <img src="image.jsp?imgID=112" width="150" heigth="130" border="0">
    I am also giving the sample jsp to display
         byte [] imgData = blob.getBytes(1,(int)blob.length());
    response.setContentType("image/jpeg");
    OutputStream o = response.getOutputStream();
    o.write(imgData);
    I want to display the image without any time taken. How could I solve this. Please Help me.
    Thanks.
    Phani.

    You should not crosspost questions. It is rude and a waste of our time.
    Please stick to one topic: [http://forums.sun.com/thread.jspa?threadID=5372144].

  • 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

  • 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?

  • Can i display all images from databases with adf jsp

    hi
    I want to display all images from the databases whit adf bussines components, because with the sample on http://www.oracle.com/technology/training/products/intermedia/index.html page, i only can display 10 images. i'd lije to know if i can to search in the databases by the id of the image.
    this is the code:
    %@ taglib uri="http://xmlns.oracle.com/adf/ui/jsp/adftags" prefix="adf"%>
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@ page contentType="text/html;charset=windows-1252"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>untitled</title>
    </head>
    <body>
    <html:errors/>
    <table border="1" width="100%">
    <tr>
    <th> </th>
    <th>
    <c:out value="${bindings.ImagenView1.labels['Id']}"/>
    </th>
    <th>
    <c:out value="${bindings.ImagenView1.labels['Descripcion']}"/>
    </th>
    <th>
    <c:out value="${bindings.ImagenView1.labels['Image']}"/>
    </th>
    </tr>
    <c:forEach var="Row" items="${bindings.ImagenView1.rangeSet}">
    <tr>
    <td>
    <c:out value="${Row.currencyString}"/>
    </td>
    <td>
    <c:out value="${Row['Id']}"/> 
    </td>
    <td>
    <adf:render model="Row.Image"/>
    </td>
    <td>
    <c:out value="${Row['Image']}"/> 
    </td>
    </tr>
    </c:forEach>
    </table>
    </body>
    </html>

    I think you want the interMedia JSP tag library...
    http://www.oracle.com/technology/software/products/intermedia/htdocs/descriptions/tag_library.html
    Larry

  • 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

Maybe you are looking for

  • Sale invoice reverse error

    Hi, expert I have enter the sales bill through T-code FB70 at the time of entry i was not enterd the Co object like -cost center or profit center after save the invoice there was some mistake now i want to reverse the document in FB08 but it show an

  • End of document in Safari Browser in New Ipad.

    Hi all, I have a site with a very long list. How can i go to the END OF DOCUMENT. in safari browser?

  • IDOC AAE error:IDOC_ERROR_PARSE_FAILURE

    Hello Gurus, I am facing following error in IDOC AAE channel scenario is SOAP to IDOC we are using Integrated configuration.I have mapped all the attributes in the IDOC to 1 and date formats are fine.On Analsys i found for the IDOC Field MENGE is not

  • Unable to modify ANY C2S configurations

    New BM3.8 server. Trying to set up VPM C2S services. When I try to modify any DEFAULT or NEW Client to Site configurations, I get this error message when I click on OK. Unable to add any new traffic or authentication rules. The Client To Site Service

  • Problems accessing metadata

    I am trying to get a particular metadata property from a file into Bridge JavaScript. I can see many metadata properties in JavaScript and the one I want is listed in the metadata panel in Bridge, but I can't see to figure out how to access it progra