Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Displaying multiple images using servlet or JSP into html table

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Displaying multiple images using servlet or JSP into html table

    Hi i require a complete code to retrieve BLOB images from Mysql database and display them all at once in rows of a table .Plz help.The table should be created dynamically ..


  2. #2
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,235
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Displaying multiple images using servlet or JSP into html table

    Thread moved from Members Introductions

    We are not a code service, so chances are slim you will get any code without more information or showing some type of effort. Suggest reading the link in my signature entitled 'Getting Help'

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to display multiple images on web page using servlet

    can i get the code to display multiple images in a webpage plz.
    here is my code . dono wat modifications should be done . i want to display all images stored in particular table at once .






    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
    //String photoid = request.getParameter("txtid");
    Blob photo = null;
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;

    String query = "select img from pic where idpic=2";
    ServletOutputStream out = response.getOutputStream();

    try {;
    conn = getMySqlConnection();
    } catch (Exception e) {
    response.setContentType("text/html");
    out.println("<html><head><title>Person Photo</title></head>");
    out.println("<body><h1>Database Connection Problem.</h1></body></html>");
    return;
    }

    try {
    stmt = conn.createStatement();
    rs = stmt.executeQuery(query);
    if (rs.next()) {
    photo = rs.getBlob(1);

    } else {
    response.setContentType("text/html");
    out.println("<html><head><title>Person Photo</title></head>");
    out.println("<body><h1>No photo found for id= 001 </h1></body></html>");
    return;
    }

    response.setContentType("image/gif");
    InputStream in = photo.getBinaryStream();
    int length = (int) photo.length();

    int bufferSize = 1024;
    byte[] buffer = new byte[bufferSize];

    while ((length = in.read(buffer)) != -1) {
    System.out.println("writing " + length + " bytes");
    out.write(buffer, 0, length);
    }

    in.close();
    out.flush();
    } catch (SQLException e) {
    response.setContentType("text/html");
    out.println("<html><head><title>Error: Person Photo</title></head>");
    out.println("<body><h1>Error=" + e.getMessage() + "</h1></body></html>");
    return;
    } finally {
    try {
    rs.close();
    stmt.close();
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }

    /**
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    * @throws ServletException if a servlet-specific error occurs
    * @throws IOException if an I/O error occurs
    */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    }

  4. #4
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Displaying multiple images using servlet or JSP into html table

    here is my code . dono wat modifications should be done . i want to display all images stored in particular webpage table all at once .






    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
    //String photoid = request.getParameter("txtid");
    Blob photo = null;
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;

    String query = "select img from pic where idpic=2";
    ServletOutputStream out = response.getOutputStream();

    try {;
    conn = getMySqlConnection();
    } catch (Exception e) {
    response.setContentType("text/html");
    out.println("<html><head><title>Person Photo</title></head>");
    out.println("<body><h1>Database Connection Problem.</h1></body></html>");
    return;
    }

    try {
    stmt = conn.createStatement();
    rs = stmt.executeQuery(query);
    if (rs.next()) {
    photo = rs.getBlob(1);

    } else {
    response.setContentType("text/html");
    out.println("<html><head><title>Person Photo</title></head>");
    out.println("<body><h1>No photo found for id= 001 </h1></body></html>");
    return;
    }

    response.setContentType("image/gif");
    InputStream in = photo.getBinaryStream();
    int length = (int) photo.length();

    int bufferSize = 1024;
    byte[] buffer = new byte[bufferSize];

    while ((length = in.read(buffer)) != -1) {
    System.out.println("writing " + length + " bytes");
    out.write(buffer, 0, length);
    }

    in.close();
    out.flush();
    } catch (SQLException e) {
    response.setContentType("text/html");
    out.println("<html><head><title>Error: Person Photo</title></head>");
    out.println("<body><h1>Error=" + e.getMessage() + "</h1></body></html>");
    return;
    } finally {
    try {
    rs.close();
    stmt.close();
    conn.close();
    } catch (SQLException e) {
    e.printStackTrace();
    }
    }
    }

    /**
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    * @throws ServletException if a servlet-specific error occurs
    * @throws IOException if an I/O error occurs
    */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    }

  5. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,170
    My Mood
    Hungover
    Thanks
    141
    Thanked 599 Times in 514 Posts

    Default Re: Displaying multiple images using servlet or JSP into html table

    I've merged your duplicate post with this one. Please read the link in my signature on asking questions the smart way before posting again.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #6
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,235
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Displaying multiple images using servlet or JSP into html table

    Please read post 2 and post 5, and the advice given therein regarding how best to ask questions to get the help you seek in an efficient manner. You other thread (3rd) thread has been removed, creating more will not get you help any sooner, in fact it will irritate moderators who must deal with them appropriately, and who will then consider taking further action.

Similar Threads

  1. Java: Links, images, font and divisions with HTML / CSS
    By Cyloc in forum AWT / Java Swing
    Replies: 3
    Last Post: August 2nd, 2011, 12:54 PM
  2. HTML table to 2D array parser
    By Neruk in forum Algorithms & Recursion
    Replies: 2
    Last Post: January 28th, 2011, 06:16 AM
  3. Saving multiple images
    By Dario in forum Java Theory & Questions
    Replies: 3
    Last Post: January 25th, 2011, 12:59 PM
  4. displaying multiple jpanels in a jframe
    By tooktook22 in forum AWT / Java Swing
    Replies: 1
    Last Post: January 19th, 2011, 12:46 PM
  5. Question About servlet and HTML
    By kurt-hardy in forum Java Theory & Questions
    Replies: 5
    Last Post: January 14th, 2011, 08:25 PM