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>

Similar Messages

  • How do I Display a string from a servlet into a JSP Page???? NEED HELP!!!!

    Hi guys,
    How do I Display a string from a servlet into a JSP Page...
    Ive tried so many bloody things!.....
    Simply.
    I get text from JSP. The servlet does what ever it does to the string.
    Now. Ive create sessions and bean things,.... how the hell do I display it in a text box... I can display on the screen.. but not in the text box.!!!
    please help!!!

    hmmm, I dont really like using JSP programming, u should be using JAVA..
    the way to do it is:
    Call and cast to the bean like this:
    <%@ page import="beans.*" %>
    <% //cast to bean get request create object
    userNameBean u= (userNameBean) request.getSession().getAttribute("userNameBean");
    then... all you do is call it like this:
    <input type="text" name="firstName" value="<%= u != null? u.getFirstName(): "" %>">
    this is the real programmers way,,,
    chet.~

  • Load and Display Multiple Images in a Web Dynpro Table

    I am new to Web Dynpro and I am wondering if anyone can help me with an application that I am currently developing. I have a particular requirement to store images in a database table (not MIME repository) and then display them in a WD table element. An image can be of JPEG, PNG or TIFF format and is associated with an employee record.
    I want to create a view in my application that displays multiple images in a table, one image per row. I want to do this using Web Dynpro for ABAP, not Java. I have looked into pretty much all examples available for Web Dynpro and came to the conclusion that Components such as WDR_TEST_EVENTS and WDR_TEST_UI_ELEMENTS do not have any examples of images being stored in a database table and viewed in/from a Web Dynpro table element. Programs such as RSDEMO_PICTURE_CONTROL, DEMO_PICTURE_CONTROL and SAP_PICTURE_DEMO do not show this either.
    The images to be displayed in the Dynpro table are to come from a z-type table, stored in a column of data type XSTRING (RAW STRING). So I would also like to know how to upload these images into this z-type table using ABAP code (not Java).
    Your help would be greatly appreciated.
    Kenn

    Hi,
    May be this is the is the correct place to post your query.
    Web Dynpro ABAP
    Regards,
    Swarna Munukoti.
    Edited by: Swarna Munukoti on Jul 16, 2009 3:52 PM

  • How to retrive multiple images from database

    Hi,
    I have to retrieve multiple images from oracle database and have to display the image in the jsp.
    I am passing imageCategoryId from the jsp.This id contain number of image in DB.
    I googled the issue and i found some solution.want to know whether what i did is correct and how i have to display the retrieved image in jsp.
    Need urgent help.Experts kindly help me.
    This is my action file.
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.naming.NamingException;
    import com.image.dao.ImageDAO;
    public class GetImageServlet extends HttpServlet{
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException{
    try{
         ImageDAO image = new ImageDAO();
    String categoryId = request.getParameter("catgId");
         bytes[] imagebyte = image.getImagesByCategoryId(categoryId);
    InputStream is = new FileInputStream(imagebyte);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bos.write(imagebyte);
    blobIs.close();
    catch(IOException e){
    e.printStackTrace();
    } catch(Exception excep) {
                        excep.printStackTrace();
    This is DAO file
    public byte[] getImagesByCategoryId(String categoryId) throws Exception
              PreparedStatement statement = null;
              ResultSet resultSet = null;
              StringBuffer queryBuffer = new StringBuffer();
              Blob image = null;
              String imageId = null;
              ArrayList imageIdLIst = new ArrayList();
              try {
                   this.connection = connManager.getDataSourceConnection();
                   queryBuffer.append("select image from Image_Table where image_category='"+categoryId+"'");
                   statement = connection.prepareStatement(queryBuffer.toString());
                   resultSet = statement.executeQuery();
                   while(resultSet.next()) {
                        image = rs.getBlob(1);
                        long imgLength = image.getBufferSize();
                        byte[] byteImage = new byte[imgLength];
                        byteImage = image.getBytes(1,(int)imgLength);
              } catch(Exception excep) {
                   excep.printStackTrace();
              return byteImage;
    How to display retrieved image in jsp.
    whether action and dao file is correct or what changes i have to do to correct the problem.
    P.S : As a Newbie i dont know how to use code tag for this java code.Kindly forgive me.
    Regards,
    hardlyUsed.

    hardlyused wrote:
    I have to retrieve multiple images from oracle database and have to display the image in the jsp.There are at least two parts to the problem.
    1. Get it from the database.
    2. Display it.
    Part 1 has nothing to do with part 2.
    You must solve 1 before you solve 2.
    Finally generically there is no such thing an "image" but rather there is binary data which is represented in such a way that it one of many formats that represent an "image".
    Knowing which specific format the "image" is stored in will at a minimum be helpful and could be required.

  • Hi , How to display multiple images

    hi,
    please help me out!
    I need to display multiple images on the jframe or on a jpanel . From the database where the path of the images are stored how to do it any one please
    give the code

    import java.awt.*;
    import java.awt.geom.AffineTransform;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.net.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    public class ShowingImages extends JPanel
        final int
            WIDTH  = 75,
            HEIGHT = 125;
        public ShowingImages()
            String[] filePaths = getPaths();
            BufferedImage[] images = getImages(filePaths);
            setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(5,5,5,5);
            gbc.weighty = 1.0;
            gbc.weightx = 1.0;
            loadImages(images, gbc);
        private void loadImages(BufferedImage[] images, GridBagConstraints gbc)
            for(int j = 0; j < images.length; j++)
                BufferedImage scaled = scale(images[j], WIDTH, HEIGHT);
                ImageIcon icon = new ImageIcon(scaled);
                if(j % 2 == 0)
                    gbc.gridwidth = GridBagConstraints.RELATIVE;
                else
                    gbc.gridwidth = GridBagConstraints.REMAINDER;
                add(new JLabel(icon), gbc);
        private String[] getPaths()
            String[] fileNames = {
                "images/redfox.jpg", "images/greathornedowl.jpg",
                "images/bclynx.jpg", "images/mtngoat.jpg"
            return fileNames;
        private BufferedImage[] getImages(String[] fileNames)
            BufferedImage[] images = new BufferedImage[fileNames.length];
            for(int j = 0; j < fileNames.length; j++)
                images[j] = loadImage(fileNames[j]);
            return images;
        private BufferedImage loadImage(String fileName)
            BufferedImage image = null;
            try
                URL url = new URL("file:" + fileName);
                image = ImageIO.read(url);
            catch(MalformedURLException mue)
                System.err.println("malformed url for image: " + mue.getMessage());
            catch(IOException ioe)
                System.err.println("unable to read image file: " + ioe.getMessage());
            return image;
        private BufferedImage scale(BufferedImage source, int w, int h)
            BufferedImage scaled = new BufferedImage(w, h, source.getType());
            Graphics2D g2 = scaled.createGraphics();
            g2.setPaint(getBackground());          // background for
            g2.fillRect(0,0,w,h);                  //   scale to fit
            double width = source.getWidth();
            double height = source.getHeight();
            double xScale = w / width;
            double yScale = h / height;
            double scale = Math.min(xScale, yScale);      // scale to fit
            //double scale = Math.max(xScale, yScale);    // scale to fill
            double x = (w - scale*width)/2;
            double y = (h - scale*height)/2;
            AffineTransform at = AffineTransform.getScaleInstance(scale, scale);
            g2.translate(x, y);
            g2.drawRenderedImage(source, at);
            g2.dispose();
            return scaled;
        public static void main(String[] args)
            // create and configure your JFrame here...
            f.getContentPane().add(new JScrollPane(new ShowingImages()));
    }

  • Can you edit multiple images from a PDF in photoshop?

    I scan a lot of old publications with images and drawings. The images are in greyscale, but my scanner produces better results set to color. As such, I have to convert the images to greyscale in Photoshop from Acrobat. I have several PS actions that make this process easier, but I wish there was a way to select multiple images from a page or PDF file and run the actions on them (a batch) instead of one at a time. Is there? Or perhaps another method than what I am doing?

    I recommend that you scan first, save as TIFF, do any desired correction, and only then make PDFs. Scanning direct to PDFs is great for simple uncomplicated workflows, but a liability when correction is needed.

  • How can I display an image from a shared-network folder?

    Hi
    Does anyone know how I can display images from within APEX that are found outside the database? What configuration have I missed?
    Within Windows-Internet-Explore I can access the following image using the below URLs, BUT I cannot access it from within APEX?
    What do I need to do so APEX can display theses images from our internal shared network folder?
    both these URLs work within Firefox (but on APEX):
    \\Saremote\UPDOWNFILES_DIR\polk_insight.gif
    file://///Saremote/UPDOWNFILES_DIR/polk_insight.GIF
    So within APEX I have created a "display as Text' Item that works with this "amazon image" syntax:
    {lessthan} IMG SRC= {doublequot} http://g-images.amazon.com/images/G/01/associates/navbar2000/logo-no-border(1).gif {doublequot} {greaterthan}
    BUT sadly not with my image:
    {lessthan} IMG SRC= {doublequot} file://///Saremote/UPDOWNFILES_DIR/polk_insight.GIF {doublequot} {greaterthan}
    Any ideas would be appreciated.
    Thanks
    Steve
    Edited by: [email protected] on Sep 12, 2008 8:30 AM
    Edited by: [email protected] on Sep 12, 2008 8:31 AM
    Edited by: [email protected] on Sep 12, 2008 8:32 AM
    Edited by: [email protected] on Sep 12, 2008 8:33 AM

    If you have a local html file, or open an image locally from the menu, then yes, it works, but with web pages that are served from a remote location (web server), security kicks in and prevents the web page from accessing local files (and files on a networked drive).
    you will either have to put the image on the web server and access it through http, or you can load it into the database/workspace images and access it that way.

  • Can I somehow let the user select multiple images from device?

    Is there any way to let the user select multiple images from the device media gallery?
    The CameraRoll only selects one image. And the FileRefernceList doesn't show thumbnails (so you have no idea what you are selecting).
    Is there a way, or maybe some sort of workaround, for this? Is there a way to maybe "read" the users gallery on the SD-card and output your own gallery that the user can select from?
    I'm developing towards both Android and iOS so cross-plattform is a must.
    Thank you guys

    +1 to this question. I'm looking to do the same thing but haven't had any luck yet.

  • Load multiple images from directory?

    What is the best way to use CF to load multiple images from a
    server directory please? I have CF calling a stored procedure that
    returns an array of file names. I am using a Flex front end, and
    wonder if I should just pass the file name array to Flex and let it
    loop through and load each image into an array. Or is it possible
    from within my CFC to use the file name array to get CF to grab the
    images and then pass that image array back to Flex? If so, is there
    any advantage to either approach? TIA,
    Mic.

    You don't want to pass the binaries to Flex, you should just
    give Flex the image names and load them via HTTP.

  • How to display multiple tables from database using netbeans swing gui

    plz reply asap on how to display multiple tables from database using netbeans swing gui into the same project

    Layered Pane with JTables or you can easily to it with a little scripting and HTML.
    plzzzzzzzzzzzzzzzzz, do not use SMS speak when posting.

  • 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

  • How do I import multiple images (from Aperture) to multiple pages in Pages?

    I can select and drag multiple images from Aperture to Pages, but they all are inserted on the same page. If I have 100 images, can I force Pages to insert one image on each of 100 pages?
    Thanks,
    Rick

    Burn for what purpose? To share with others?
    Export the photos to a folder on the Desktop. Burn that with the Finder. Result: a folder of images that any computer can read.
    Using iPhoto's Burn command creates an iPhoto Library on the disk and is suitable only for others also using the same version of iPhoto.
    This User Tip
    https://discussions.apple.com/docs/DOC-4921
    has details of the options in the Export dialogue.
    Note that rewriteable disks do not necessarily mean that you can append files to them, and require special burning software to do so.
    Regards
    TD

  • Saving multiple images from

    Are there any updated functions or apps that would allow you to save multiple images from a text message to camera roll from iphone? If not, what are the best alternatives these days?

    Some apps, like Mail allow you to do this but others do not. Tap on photo and a list of choices comes up. In Mail one of the choices is to Save X Photos where X equals the number of photos in the email. I've never received more than one photo in a text so I'm not sure if this same choice will appear there.

  • Display an image from an array of bytes

    Hi, I'm trying to display an image from the raw pixel values. lets say i read a bmp file to an array, chuk the header off and want to display the pixel. How can I do this? I don't want any file formats, just want to display the pixels and creat the image. Is this possible?
    Many thanks,
    H

    Thanks for the reply. I had a look at MemoryImageSource and other classes that relates to it. I wrote the example given, but it doesn't identify createImage(). I've implemented ImageProducer, but still complains. Have you any idea why? Thanks for your help.
    H

  • Multiple images of the same file on one page

    How do I create multiple images of the same file on one page? For example, I've got an image that I could fit 6 of on one page, and would like to print it that way instead of printing it on 6 individual pieces of paper.

    Are you attempting to do this in Adobe Workspaces? Or are you looking for software that will do it?
    If the former, you could insert the image into a Buzzword document six times. Not exactly elegant, but it might do the trick.

Maybe you are looking for

  • [SOLVED] upgrade using Octopi system will not boot into DM

    I did a system upgrade using Octopi late last night. I use Enlightenment and Gnome. After the upgrade the desktop froze (E), so I switched to a vt and rebooted. That failed to work, so I forced power off using the power button and went to bed. The ne

  • Dynamically change the db and server in execute sql task

    Pkg 2: Moves data from B_STG (Staging DB) to B_Det_STG (Staging DB)  ---- option1 Pkg 3: Moves data from B_STG (Staging DB) to B_Det (PC DB)   ---- option2 This part is duplicating in both the packages So they want me to merge both of them into in ex

  • Can't get rid of unwanted square on video

    I need help removing a lined border from around my video. I'm not sure how it got there any tips are most welcome

  • Submit form doesn't work in edge Inspect

    I have a contact form in my web and when i submit a form that doesn't work in edge inspect. Edge Inspect after a short time program stops working unfortunately. Form is not submitting and email also is not send. I have a form and i use AJAX to send f

  • Change Currency in Venezuela

    Please, I like to know if someone has some information how will SAP treat the change currency in Venezuela at the beginning of 2008. Any information will be very good. Thanks