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 ..
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'
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 {
}
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 {
}
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.
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.