Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet displaying both image and records problem in jsp and servlet
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


dipo
displaying both image and records problem in jsp and servlet
3 Answer(s)      6 years and 4 months ago
Posted in : JSP-Servlet



Advertisement
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:-)



Related Tutorials/Questions & Answers:
displaying both image and records problem in jsp and servlet - JSP-Servlet
displaying both image and records problem in jsp and servlet  hello... the application to display more than one employee records and their pictures. e.g. say i'm having records like: firstname, lastname, empid, department, salary, job_title
displaying images and records problem - JSP-Servlet
displaying images and records problem  hi, Thanks for your reply... display any record and image. I posted my question and since then no replay. Please, kindly help me to solve the problem urgently. Or in any other way to do
Advertisements
displaying employee records and their images problem - JSP-Servlet
displaying employee records and their images problem  hi, Thanks for your reply to my question. The code you sent to me yesterday was not working. it doesn't display any record and image. Please, help me out urgent
display records with images problem - JSP-Servlet
with a unique id. Also i wrote i jsp that link to servlet in order to display...display records with images problem  hello, i am developing HR application whereby i want to display employee records and their pictures on web
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
jsp image problem - JSP-Servlet
jsp image problem  hi everyone, How to display multiple images from mysql database to jsp page. please help me
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
Problem displaying resultset in jsp(no frameworks used) - JSP-Servlet
Problem displaying resultset in jsp(no frameworks used)  Problem... if the resultset return 25 rows, these 25 records are to be displayed in my jsp. My problem area: a) How to display the records within JSP from request>arraylist>
Displaying image when clicked on URL in jsp - JSP-Servlet
Displaying image when clicked on URL in jsp  Hi, I am using... in displaying the image from the folder. Regards, Anish... For Screenshot : abc.jpg here abc.jpg is a url and when clicked would show me an image
Image problem Urgent - JSP-Servlet
Image problem Urgent  Respected Sir/madam, I am R.Ragavendran.. Actually I got your coding.. But This code is not enabling the user to click and change the image.. I request you to remember the code which you have
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
Displaying Rows - JSP-Servlet
Displaying Rows  Hi, I need your support on how to display data from... servlet or jsp  Hi friend, This is form code, display data in servlet Display Data In Servlet
Name Displaying - JSP-Servlet
vijayababu.m@cybermateinfotek.com  Hi AJAX and Servlet var
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 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
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 <
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
jsp problem - JSP-Servlet
jsp problem  here is a code for Retrieving image from mysql database through jsp. but i cann't set size of image when it was display so what should... me abt it, here is code for both insert and retrieve image form database and its
jsp problem - JSP-Servlet
jsp problem  here is a code for Retrieving image from mysql database through jsp. but i cann't set size of image when it was display so what should... me abt it, here is code for both insert and retrieve image form database and its
How to check no records - JSP-Servlet
How to check no records  Hi all, I am developing an onlineshopping project, in that how i have 2 check no records. I saw an answer, but is for finding not null only... ie, if(rs!=null) But i need the null checking
Servlet Problem - JSP-Servlet
Servlet Problem  Hii I am Ajay . I am makin g a project in java... with that image. But when ever I try to dispaly it. Either the image gets displayed r textual info but not the both. Can u plzz help me
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
printing records from jsp - JSP-Servlet
printing records from jsp  Hi Plz tell me how to printing out pages..., For paging in Jsp visit to : http://www.roseindia.net/jsp/paging.shtml http://www.roseindia.net/jsp/bank.shtml Thanks
JSP Problem - JSP-Servlet
JSP Problem  Hi, I have problem,this is my senario I have one jsp,this jsp having the 3 fields.let me take 3fields userName,emailAddress... and insert in to the data base(i mean 5 records should be saved when ever i click
image displaying in java
image displaying in java  how to display an image by using load image button in applet viewer
image in jsp - JSP-Servlet
image in jsp  i m storing path of image in my database.. but when i m trying to display image using that path image is not getting... i m storing path like c:\image\a.jpg ... and i m using tag... how to get
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
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
Image - JSP-Servlet
Image  Hi Experts, I need your help (Source Code)on how I can send and retrieve image to/from Microsoft Sql 2000 database (NOT MYSQL) using java servlet or Jsp and html form. Please the output should be displayed in an html form
 

 

 

DMCA.com