displaying both image and records problem in jsp and servlet

Ads
 

displaying both image and records problem in jsp and servlet

View Answers

September 18, 2008 at 5:15 PM

Hi friend,


Code to help solve the problem.


<%@ page import="java.sql.*,java.io.*,java.util.*" %>
<HTML>
<HEAD>
<TITLE>Download Images</TITLE>
</HEAD>

<BODY>
<br><br>
<table align="center" border=0 width="200px">
<tr>
<td colspan=2 align="center"><b>Employee Record</b></td>
</tr>
<tr><td colspan=2>&nbsp;</td></tr>
<%

String connectionURL = "jdbc:mysql://localhost:3306/userdetails";;
Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection(connectionURL,"root","root");
Statement stmt=con.createStatement();
String strQuery = "select id from imageupload";
ResultSet rs = stmt.executeQuery(strQuery);
int sno=0;
while(rs.next())
{
sno++;
%>
<tr style="background-color:#efefef;">
<td><b><%=sno%></b></td>
<td><b><%=rs.getString("firstname")%></b></td>
<td><b><%=rs.getString("lastname")%></b></td>
<td><b><%=rs.getInt("empid")%></b></td>
<td><b><%=rs.getString("department")%></b></td>
<td><b><%=rs.getInt("salary")%></b></td>
<td><b><%=rs.getString("job_title")%></b></td>
<td align="center">
<a href="image.jsp?imgid=<%=rs.getInt(1)%>">
<img src="image.jsp?imgid=<%=rs.getInt(1)%>" width="50" height="50">
</a></td>
</tr>
<%
}
rs.close();
con.close();
stmt.close();
}
catch(Exception e)
{
e.getMessage();
}
%>
</table>
</BODY>
</HTML>

September 18, 2008 at 5:27 PM

"image.jsp"

<%@ page import="java.sql.*,java.io.*,java.util.*" %>
<%

String connectionURL = "jdbc:mysql://localhost:3306/userdetails";;
if(request.getParameter("imgid")!=null && request.getParameter("imgid")!="")
{
int id = Integer.parseInt(request.getParameter("imgid"));

String filename = "image"+id+".jpg";
Connection con=null;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
con=DriverManager.getConnection(connectionURL,"root","root");
Statement st1=con.createStatement();
String strQuery = "select imagefile from imageupload where id="+id;

ResultSet rs1 = st1.executeQuery(strQuery);

String imgLen="";
if(rs1.next()){
imgLen = rs1.getString(1);
}
rs1 = st1.executeQuery(strQuery);
if(rs1.next()){
int len = imgLen.length();
byte [] rb = new byte[len];
InputStream readImg = rs1.getBinaryStream(1);
int index=readImg.read(rb, 0, len);
st1.close();
response.reset();
response.setContentType("image/jpg");
response.setHeader("Content-disposition","attachment; filename=" +filename);
response.getOutputStream().write(rb,0,len);
response.getOutputStream().flush();
}
}
catch (Exception e){
e.printStackTrace();
}
}
%>


Thanks


November 2, 2012 at 12:45 AM

A tons of thanks to u bro it worked. u saved me from HEll:-)

Ads









Related Tutorials/Questions & Answers:
How to Insert image and data both together in database in JSP/Servlet ?
How to Insert image and data both together in database in JSP/Servlet ?  //form.jsp <%@ page language="java" %> <HTML> <HEAD>... image String nn=request.getParameter("name"); String cc=request.getParameter
Data displaying with limited records in jsp
Data displaying with limited records in jsp  How to display table with limited 10 records , after clicking next button another 10 records from database upto last record please help me
Advertisements
Retrieving newly inserted records and displaying in jsp forever
Retrieving newly inserted records and displaying in jsp forever  Sir, here is my requirement, First i have to retrieve newly added 10 records from... those records in the jsp. If the session-duration exceeds 10 minutes for any
Displaying image using jsp and spring.
Displaying image using jsp and spring.  how to display an image stored in WEB-INF/images folder on the browser using jsp and spring
JSP - Problem of displaying result at webpage
JSP - Problem of displaying result at webpage  Can anyone please help to solve my problem below. My webpage has problem in displaying result position. The result should be display below my title. How do i solve it? Thank you so
Java Servlet Problem - JSP-Servlet
Java Servlet Problem  I have a servlet class that implemets..., but in the attributeReplaced() method, i want to perform a redirect to another servlet... method. Please help!!  Hi friend, Please explain problem
Image retrieval in Servlet and JSP
Image retrieval in Servlet and JSP  Sir, How should i give dynamic paths to image in JSP. EX : `<img src="C:\Users\Public\Pictures\Sample... to retrieve the image with name 001.jpg. I have no idea as to how should i
displaying List of records from database in a jsp using ajax
displaying List of records from database in a jsp using ajax  Sir, I...; In between the <div></div> I have to display the records. I am displaying... it is not right way. I have written a following servlet to get the records from
image display - JSP-Servlet
image display  how to display image that store in mysql database... column have BLOB datatype....  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/retrieve-image.shtml Thanks
JSP code problem - JSP-Servlet
JSP code problem  HI.. I have a DB2 stored procedure wich return a result set. I have made a report basing on this procedure using Crystal Reports. How to pass parameters to this procedure with java code in a JSP page
forwarding request to a jsp from a filter and displaying image in that jsp
forwarding request to a jsp from a filter and displaying image in that jsp ... correctly, but in login.jsp the image is not displaying. Can you help me in resolving this problem. Thanks & Regards, Suresh   Jsp Display Image <
Crop image Using JQuery, servlet or JSP.
Crop image Using JQuery, servlet or JSP.  Hi sir I need the code of Cropping image using JQuery with the help of servlet or JSP. I need both the code Client side as well as of server side. Please Help me
problem in record viewing in jsp - JSP-Servlet
and servlet and back end mysql actually what is my problem is i have to everytime...problem in record viewing in jsp  hai i send the code can you please find where is the problem it is not showing any error but i cannot able to view
Problem in record viewing in jsp - JSP-Servlet
Problem in record viewing in jsp  hai i have developed the application using jsp,servlets in eclipse ide i have to insert,delete,update and view . no problem all are working but in view part alone some problem i dont know what
How to retrieve image from database using jsp and servlet?
How to retrieve image from database using jsp and servlet?  Hi, I am trying to find code for displaying the image from database in a JSP page. How to retrieve image from database using jsp and servlet
problem at the time of execution - JSP-Servlet
problem at the time of execution  when i was running web applications the exception i.e 404 resource is not available what it means and where it occures what is the solution   Hi Friend, This error occurs when
Insert Image In DB through Servlet - JSP-Servlet
Insert Image In DB through Servlet  Dear Sir, My previous Query that: I want to add the Image In databse using servlet. I have a program Its fine... image in Database using servlet to visit.... http://www.roseindia.net
Upload and display image and text records using JSP and Oracle
Upload and display image and text records using JSP and Oracle  Hi all, I'm using JSP and Oracle 10g. I could retrieve and display records... the image ( uploaded by the user) and retrieve it along with the other records. Please
Uploading an image into the table - JSP-Servlet
Uploading an image into the table  how to upload an image into the table in java  Hi friend, Code to help in solving the problem... binary stream of given image. FileInputStream fis; try { // Load JDBC
Image is not displaying
Image is not displaying  Hii i am using spring javamail with html template to send mail,i am facing that image displaying prob when mail have to cm in gmail,in template just i am giving my current location of image which
displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me
displaying List of records from database in a jsp using ajax, onclick it should display the results ?? its urgent can u help me   displaying List of records from database in a jsp using ajax, onclick it should display the results
How display a image on servlet from file upload - JSP-Servlet
How display a image on servlet from file upload  Dear Sir, My issue is: How display a image on servlet from file upload I receive your answer today. That is: Answers Hi friend, I am sending running code. Image
displaying image
displaying image  how to upload image and retrieve it form database mysql in php?   Here is an example of uploading image using php. 1)form.html: <form method="post" enctype="multipart/form-data" action="upload.php
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  Dear All, I am facing some problem image uploading in server that i working fine in my system, OS Ubuntu...) com.oreilly.servlet.MultipartRequest.(MultipartRequest.java:89) org.apache.jsp.jsp.BSAdminProductsCreate_jsp
How to display image in jsp from database using Servlet?
How to display image in jsp from database using Servlet?  Hi, How to display image in jsp from database using Servlet? Thanks   Hi, You will find code and example program at Retrieve image from database using Servlet
save multiple records into database using jsp/servlet mvc
save multiple records into database using jsp/servlet mvc  hai, this is my jsp where i have enter multiple username and password and save...; </table> </form> after add user click pass values to servlet
Image upload in mysql database using jsp servlet
Image upload in mysql database using jsp servlet  Hello, I need code to insert image in mysql database, I have seen the code which is already in your portal but it is not inserting image into database it save in the folder
retrive the employee details with image from mysql database using jsp servlet
retrive the employee details with image from mysql database using jsp servlet  im doing the web project to retrive the employee profile which i stored in the database using jsp servlet then want to show the result in the next jsp
Retrieve image from database using servlet and display in JSP
Retrieve image from database using servlet and display in JSP  Hi, I... to use MySQL Database from JSP page. How to retrieve image from database using servlet and display in JSP? Thanks
Very urgent Image Selection - JSP-Servlet
Very urgent Image Selection  Respected Sir/Madam, I am R.Ragavendran.. If you are telling that your coding works fine, then can u plz tell me..., R.Ragavendran..  Hi friend, Your Problem in stateChanged() function
problem in creating web application using servelet, jsp, jdbc and xml - JSP-Servlet
problem in creating web application using servelet, jsp, jdbc and xml  Using Servlet, JSP, JDBC and XML create a web application for a courrier... the technologies JSP,Servlet and JDBC etc... Thanks

Ads