<%@page import="com.image.vo.ImageDetailsVO"%>
<%@page import="com.image.controller.Global"%>



<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Image" id="image" method="post">
        <table>
            <tr>
                <td><strong>UserId:-</strong></td>
                <td><input type="text" name="name"><br> <br></td>
            </tr>

            <tr>
                <td></td>
                <td><input type="submit" name="submit" value="submit" /></td>
            </tr>

            <%
                        if (Global.imageDetailsVOs != null
                                && Global.imageDetailsVOs.size() > 0) {
                            for (int i = 0; i < Global.imageDetailsVOs.size(); i++) {
                                ImageDetailsVO imageDetailsVO = Global.imageDetailsVOs
                                        .get(i);
                    %>




                    <tr>


                        <td><%=imageDetailsVO.getName()%></td>
                        <td><%=imageDetailsVO.getId()%></td>
                        <td><%=imageDetailsVO.getCity()%></td>
                        <td><%=imageDetailsVO.getImage()%></td>
                        <td><%=imageDetailsVO.getPhone()%></td>



                    </tr>



                    <%
                        }
                        }
                    %>

        </table>
    </form>

</body>
</html>

package com.image.vo;

import java.sql.Blob;

public class ImageDetailsVO {

    private int id;
    private String name;
    private String city;
    private long image;
    private String Phone;
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getCity() {
        return city;
    }
    public void setCity(String city) {
        this.city = city;
    }
    public long getImage() {
        return image;
    }
    public void setImage(long image) {
        this.image = image;
    }
    public String getPhone() {
        return Phone;
    }
    public void setPhone(String phone) {
        Phone = phone;
    }
    public void setImage(Blob blob) {
        // TODO Auto-generated method stub

    }



}

package com.image.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.image.vo.ImageDetailsVO;



public class ImageDAO {

    Connection connection;
    Statement statement;


    public ImageDAO(){

        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/mahendra","root","");
            statement = connection.createStatement();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public List<ImageDetailsVO> getImageDetailsVOs(ImageDetailsVO vo) {

        List<ImageDetailsVO> list = new ArrayList<ImageDetailsVO>();


        try {

            System.out.println(vo.getId());
            String sql ="SELECT * FROM save_image where name='"+vo.getName()+"'";
            ResultSet rs= statement.executeQuery(sql);
            System.out.println(rs+"Result Set");
            statement = connection.createStatement();

            while(rs.next())
            {
                System.out.println(rs.getInt(1));
                ImageDetailsVO imageDetailsVO = new ImageDetailsVO();
                imageDetailsVO.setId(rs.getInt(1));
                imageDetailsVO.setName(rs.getString(2));
                imageDetailsVO.setCity(rs.getString(3));
                imageDetailsVO.setImage(rs.getBlob(4));
                imageDetailsVO.setPhone(rs.getString(5));

                list.add(imageDetailsVO);
            }



        } catch (Exception e) {
            e.printStackTrace();
        }

        return list;
    }

}


package com.image.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.image.dao.ImageDAO;
import com.image.vo.ImageDetailsVO;


@WebServlet("/Image")
public class Image extends HttpServlet {
    private static final long serialVersionUID = 1L;
    boolean Check = false;


    public Image() {

    }


    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        try {

            ImageDetailsVO imageDetailsVO = new ImageDetailsVO();           

            System.out.println("Id :: "+request.getParameter("name"));
            imageDetailsVO.setName(request.getParameter("name"));


            ImageDAO dao = new ImageDAO();
            List<ImageDetailsVO> ImageDetailsVO = dao.getImageDetailsVOs(imageDetailsVO);


            for (ImageDetailsVO vo : ImageDetailsVO) {

                System.out.println("Phone "+vo.getPhone());
                System.out.println("Image "+vo.getImage());
                System.out.println("city "+vo.getCity());
                System.out.println("Name "+vo.getName());
                System.out.println("id "+vo.getId());

            }
            Global.imageDetailsVOs = ImageDetailsVO;
            response.sendRedirect("index.jsp");
        }catch(Exception e){
            e.printStackTrace();

        }   }



    }

package com.image.controller;

import java.util.List;

import com.image.vo.ImageDetailsVO;

public class Global {

    public static List<ImageDetailsVO> imageDetailsVOs;

}

Is this sample code for our enlightenment, or is there a question you wanted to ask about it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.