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

 
 


dipo
displaying both image and records problem in jsp and servlet
3 Answer(s)      4 years and 8 months ago
Posted in : JSP-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:-)









Related Pages:
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 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
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
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
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>
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 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
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
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
jsp image problem - JSP-Servlet
jsp image problem  hi everyone, How to display multiple images from mysql database to jsp page. please help me
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
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
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
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
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
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 <
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
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
tomcat problem - JSP-Servlet
with both j2sdk 1.4.2_07 and 1.5 version with tomcat 5.0.25 v. For both versions... perfectly. Kindly let me know what is the problem at an earliest. Thanking... found your problem.. http://www.roseindia.net/web-application-server/tomcat
JSP and Servlet sort - JSP-Servlet
JSP and Servlet sort  Hi I have 3 records in my database. I want... for displaying them in the jsp: Universal Books Home Page...; Hi friend, Plz specify u r problem with this code : Thanks
Array problem - JSP-Servlet
number of records.. I need to select the radio button.. After selecting..... Bur my problem is that if the pop up window contains only 1 record
arraylist problem - JSP-Servlet
my code once again only in which i m facing the problem. /* * To change... { /** * Processes requests for both HTTP GET and POST methods. * @param request servlet request * @param response servlet response
displaying image in awt - Java Beginners
displaying image in awt  Hi All, I have downloaded the code to display image using awt from here and when I execute the code I am getting... found : java.awt.Image required: Image image = tool.getImage("D
How display a Image on servlet from file upload - JSP-Servlet
How display a Image on servlet from file upload  Dear Sir, I were ask a question that How display the Image on servlet through file upload. Today I get your answer. But Sir, It code not display the image on servlet
arraylist problem - JSP-Servlet
extends HttpServlet { /** * Processes requests for both HTTP GET and POST methods. * @param request servlet request * @param response servlet response */ /* * To change this template, choose Tools
JSP code problem - JSP-Servlet
JSP code problem  Hi friends, I used the following code for uploading an image file. After compilation it shows the required message, "Image successfully uploaded", but when i try to retrieve the image I'm unable to do
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
Inserting Image(s) - JSP-Servlet
Inserting Image(s)  Hello, I need sample code using java servlet and html form and explanation on how to insert and retrieve image from mysql.  Hi friend,This is insert image code.import java.sql.*;import java.io.
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
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
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
Insert Image In DB through Servlet - JSP-Servlet
Insert Image In DB through Servlet  Dear Sir, I want to add the Image In databse using servlet. I have a program Its fine run on command prompt...()); } } } Whether Any entry will be made in web.xml when Insert Image in Databse using servlet
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
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
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..., To insert image in Database using servlet to visit.... http://www.roseindia.net
Image Program Urgent - JSP-Servlet
Image Program Urgent  Respected Sir/Madam, I am R.Ragavendran.. Actuaaly in the Image Selection coding which is produced below, I am getting... selected ID in my text box.. Hope you remember my Problem and Understand the same
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
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
Displaying Date in jsp - JDBC
Displaying Date in jsp  I want to insert Date of birth of a person in a database.i am getting input value from HTML and i use jsp application to interact with database.My JSP code for inserting Date is below: String dateStr
jsp - excel generating problem - JSP-Servlet
jsp - excel generating problem  Hi, I worked with the creating excel through jsp, which is the first example in this tutorial.... I cant view in web page as the tutorial image shows. Kindly give solution
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
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 image with byte array[] - Java Beginners
Displaying image with byte array[]  Hi Frndz.. As per my requirement i need to show an image by using an byte array object which have image data.../article-992927-6.html Here it describe how display image in jsp. Sorry I have
Insert Image in DB through Servlet - JSP-Servlet
Insert Image in DB through Servlet  Dear Sir, I am not able to solve my problem cocerning Inserting the image in Database through Servlet. I am usng...("***********"); System.out.println("Successfully display image from databse
Upload Image to Database through Servlet - JSP-Servlet
Upload Image to Database through Servlet  Hello, I make a application from where I upload the Image from local disk then store in DB.Before storing the Image in DB I want to check this program. I include the commons
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

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.