image display

image display

hello sir this is saurav srivastav, I am developing my website I have seen all the results of displaying and I got some good code for uploading image in ms access database and also seen the result of displaying image from access database but Sir I want that how I display image from database on a given position in a DIV tag in JSP kindly help me, I have to show my project in a competition..Plz plz help me. Thank you in advance....

View Answers

January 16, 2012 at 11:48 AM

Follow these steps:

1)Go to the start>>Control Panel>>Administrative Tools>> data sources.

2)Click Add button and select the driver Microsoft Access Driver(*.mdb).

3)After selecting the driver, click finish button.

4)Then give Data Source Name and click ok button.

5)Your DSN will get created.

6)Create table user(id(Number),image(OLE Object)).

6) Restart your server and run your jsp code.

<%@page import="java.sql.*,java.io.*"%>
<%
try{
    InputStream sImage;
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
           Connection con = DriverManager.getConnection("jdbc:odbc:student");
File imgfile = new File("C:/rose.jpg");
      FileInputStream fin = new FileInputStream(imgfile);
      PreparedStatement pre = con.prepareStatement("insert into user(image) values(?)");
      pre.setBinaryStream(1,fin,(int)imgfile.length());
      pre.executeUpdate();
     out.println("Inserting Successfully!");
      pre.close();
      Statement st=con.createStatement();
      ResultSet rs=st.executeQuery("SELECT image FROM user");
      if(rs.last()) {
byte[] bytearray = new byte[1048576];
int size=0;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
while((size=sImage.read(bytearray))!= -1 ){
response.getOutputStream().write(bytearray,0,size);
}
}
 con.close();
}     
catch(Exception ex){
out.println("error :"+ex);
}
%>

Here student our dsn.


January 16, 2012 at 12:07 PM

1)page.jsp:

<%@ page language="java" %>
<HTML>
<HEAD><TITLE>Display file upload form to the user</TITLE></HEAD>
<BODY> <FORM ENCTYPE="multipart/form-data" ACTION="upload.jsp" METHOD=POST>
<br><br><br>
<center>
<table border="0" bgcolor=#ccFDDEE>
<tr>
<center>
<td colspan="2" align="center"><B>UPLOAD THE FILE</B><center></td>
</tr>
<tr>
<td colspan="2" align="center"> </td>
</tr>
<tr>
<td><b>Choose the file To Upload:</b></td>
<td><INPUT NAME="file" TYPE="file"></td>
</tr>
<tr>
<td colspan="2" align="center"> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Send File"> </td>
</tr>
<table>
</center>
</FORM>
</BODY>
</HTML>

2)upload.jsp:

<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.zip.*"%>
<%
String saveFile="";
String contentType = request.getContentType();
if((contentType != null)&&(contentType.indexOf("multipart/form-data") >= 0)){
DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();
byte dataBytes[] = new byte[formDataLength];
int byteRead = 0;
int totalBytesRead = 0;
while(totalBytesRead < formDataLength){
byteRead = in.read(dataBytes, totalBytesRead,formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
saveFile = file.substring(file.indexOf("filename=\"") + 10);
saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\""));
int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
int pos;
pos = file.indexOf("filename=\"");
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;
int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
File ff = new File(saveFile);
FileOutputStream fileOut = new FileOutputStream(ff);
fileOut.write(dataBytes, startPos, (endPos - startPos));
fileOut.flush();
fileOut.close();
%><Br><table border="2"><tr><td><b>You have successfully upload the file:</b>
<% out.println(saveFile);%></td></tr></table>
<%
Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/test";
ResultSet rs = null;
PreparedStatement psmnt = null;
FileInputStream fis;
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
File f = new File(saveFile);
psmnt = connection.prepareStatement("insert into image(images) values(?)");
fis = new FileInputStream(f);
psmnt.setBinaryStream(1, (InputStream)fis, (int)(f.length()));
int s = psmnt.executeUpdate();
if(s>0){
System.out.println("Uploaded successfully !");
}
else{
System.out.println("Error!");
}
}
catch(Exception e){e.printStackTrace();}
}
%>









Related Tutorials/Questions & Answers:
image display
to display in image from databse plz help me i will wait for ur reply...image display  sir the answer which you have sent to me is already I have I want to know that the syntax which you have writen for display
image display
to display in "div image from databse /div" plz help me i will wait for ur reply...image display  sir the answer which you have sent to me is already I have I want to know that the syntax which you have writen for display
Advertisements
image display
for uploading image in ms access database and also seen the result of displaying image from access database but Sir I want that how I display image from database...image display  hello sir this is saurav srivastav, I am developing my
Display image
Display image  How to Pass image from html to jsp and display that image using jsp   Here is an example that pass an image path from the html page to jsp page and display it. 1)page.html: <%@ page language="java
image display
image display  Hai Friends..... Actually I uploaded filepath into database and image into a folder. Now i want to show that image as my profile photo. How it is?...Friends Can you help me? Thanks in advance to take time
image display
image display  Hai Friends..... Actually I uploaded filepath into database and image into a folder. Now i want to show that image as my profile photo. How it is?...Friends Can you help me? Thanks in advance to take time
display an image on my page
display an image on my page  How can I display an image on my page
how to display image with listview
how to display image with listview  How can i display the list view with the related images from database
display image on jsp
display image on jsp  how to display image from database which path is coming in string. i want to display image and its discription and price... is downloading on jsp. show i can open it. but i want to display that image on jsp
Image display in pdf
Image display in pdf  i am trying to display a image in pdf using xsl fo but " [ERROR] Error while creating area : Error with image URL: images... go through the following link: Display image in pdf
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
display image using jsp
display image using jsp  display image using jsp and phonegap on emulator of eclipse   Here is a simple jsp code that displays an image on browser. <%@ page import="java.io.*" %> <%@page contentType="image/gif
image display - Java Beginners
image display  i need to display all the images from the folder and i dont want give the image path.dynamically it should display. please help  Hi friend, Code to help in solving the problem var
Jsp Image Display
Jsp Image Display  Hi,i need to display image in a Box like in profile photo,when i click on the browse button,file gets open and the selected image...;<TITLE>Display file upload form to the user</TITLE></HEAD> <
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in image tag but i am...(); response.setContentType("image/jpg"); response.getOutputStream().write(rb,0,len
Display Image in Java
Display Image in Java     ...): Pass the boolean value as true to display the image or Vice-Versa. Here we are passing the boolean value as true to display the image on the frame
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in tag but i am...); response.getOutputStream().flush(); } i think, this code will display image
JSP:select image for db and display in image tag
JSP:select image for db and display in image tag  Hi, i am new to this forum. My query is that, i am trying to display image in tag but i am...); response.getOutputStream().flush(); } i think, this code will display image
how to display the image in center - Ajax
how to display the image in center  i want to dispaly the image as center of the screen using javascript..while i am clicking the button ..any one give me the code for this one
image display - Java Beginners
HACKED BY BACTRAN  HACKED BY BACTRAN  Hi friend,<%@ page language="java" import="java.sql.*,java.util.*,java.text.*" %><html><head><title>Retrive Image with jsp</title>
image display in jsp - Java Beginners
image display in jsp  i uploaded the image and how can i print that image in next jsp page....  Hi friend, read for more information, http://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml
jsp image display
jsp image display  this is my saveImage.jsp file: <% ServletContext context = pageContext.getServletContext(); String initPath...); String updateQuery="update stu_info set image_path=? where
J2me image display - Java Beginners
J2me image display  How can i display a jpeg image in j2me  Hi Friend, Please visit the following links: http://www.roseindia.net/j2me/append-image.shtml http://www.roseindia.net/j2me/image-item-example.shtml
Display Image on JDesktopPane
Display Image on JDesktopPane In this section, you will learn how to retrieve an image from  the database and display it on the JDesktopPane. You can see... != null) { JFrame f = new JFrame(); f.setTitle("Display Image From
Display both image and data into Swing JTable
Display both image and data into Swing JTable  How To Display both image and data into Swing JTable which is retrieved from MySQL database
java image display - Java Beginners
java image display  How to display images in the folder dynamically with out using database using java and jsp  Hi friend, Code to help in solving the problem var galleryarray=new Array
How to display image in Swing?
How to display image in Swing Application? Swing is used... requirement to display the image in your swing application then you can learn to display image in swing application here. In this example user enters the name
How to display image in Swing?
How to display image in Swing Application? Swing is used... requirement to display the image in your swing application then you can learn to display image in swing application here. In this example user enters the name
display the generated image from byte array - Struts
display the generated image from byte array  how to create image from byte array using struts and display it in struts html.please give me the sample code
Display Image using Toolkit.getImage()
Display Image using Toolkit.getImage()       This section illustrates you how to display the specified image using Toolkit.getImage() method. To display the image, put an image
how to display one image on jsp through java
how to display one image on jsp through java  Hi, I wanted to display one image on my jsp file like social networking sites. But the scenario is that the image file is not inside the project folder. That is inside the C
How to retrieve and display image from database in Java?
How to retrieve and display image from database in Java?  Hi, I am... on the web page. My application is in Java/JSP. How to retrieve and display image.... Please check the it at How to store and retrieve image from database in JSP
Display image in the applet
Display image in the applet   ... illustrates you to display image in an applet which has been done in this example... and it's properties have been used to display the image in an applet. In this program only
Write an applet to display scrolling image in an applet window using thread.
Write an applet to display scrolling image in an applet window using thread.  Write an applet to display scrolling image in an applet window using thread
how to display or retrive an image in jsp whose path is stored in oracle database
how to display or retrive an image in jsp whose path is stored in oracle database  how to display or retrive an image in jsp whose path is stored in oracle database and the image is stored in my pictures folder
image is display from path of mysql database
image is display from path of mysql database  <%@ page import="java.io.,java.sql.,java.util.zip.*" %> <% String saveFile=""; String contentType = request.getContentType(); if((contentType != null)&&
pre Page load display an image loading - JSP-Servlet
pre Page load display an image loading  hi, We have requirement... to display a loading image. How to achieve this requirement. Thanks Manu  Hi Friend, Do you want to display image before loading page? Please clarify
how to display image from byte arry - Java Magazine
how to display image from byte arry  Hi.. How to display a image using byte array[] object , which have the image data in binary format. If it can be resolved , itz very helpful for me. Regards Rajesh
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
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 from database. But i couldnot retrieve and display image. I want to store
how to display image and text in single jsp page from the mysql database
how to display image and text in single jsp page from the mysql database  hello please help me to display the image and text in single jsp page from mysql database if have any reference code please send me Thanks in advance
Retrview image from sqlserver2000 and display in jsp - JSP-Servlet
Retrview image from sqlserver2000 and display in jsp  How to retreview image from sqlserver2000 to jsp? pls give the solution i am using Tomcat 4 Database Server:SQLSERVER2000 pls give the full coding  Hi friend
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
How display a image on servlet from file upload - JSP-Servlet
How display a image on servlet from file upload   Dear Sir, My Question is: How display a image on servlet from file upload Your Answer: Hi... reason is inaccessible Thanks Sir, But Servlet page nothing display any type
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
How display a Image on Servlet from file upload - JSP-Servlet
How display a Image on Servlet from file upload  Dear Sir, My requirement is I want to display a Image on Servlet from File Upload. But It not display on servlet,Its appear a downloaded form and downloaded on disk when click
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
display
display  please tell me how to display the content from database.. if we click on any image using servlets/jsp...please
Display image on JSP page using XML
Display image on JSP page using XML  ... can display a image on JSP page by using XML.  This example will examine... are stored. What we need is to extract the image file from the XML file. ADS
display multiple image file or pdf file in multiple column of a row from server or database
display multiple image file or pdf file in multiple column of a row from server... want to display that file to the user page but I want to display that file in a particular format i.e I have to display more than one files in multiple columns

Ads