Image uploading
Hi,can anyone explain the following code.
The code related to uploading an image file to oracle database using java servlet.
CODE
import java.io.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
public class AddPhotoServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
// Apache Commons-Fileupload library classes
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(factory);
if (! ServletFileUpload.isMultipartContent(request)) {
System.out.println("sorry. No file uploaded");
return;
}
// parse request
List items = sfu.parseRequest(request);
FileItem id = (FileItem) items.get(0);
String photoid = id.getString();
/* String photoid=request.getParameter("id");*/
FileItem title = (FileItem) items.get(1);
String phototitle = title.getString();
//String phototitle = request.getParameter("title"); */
// get uploaded file
FileItem file = (FileItem) items.get(2);
/*String s=request.getParameter("photo");
File file=new File(s);
FileInputStream fin = new FileInputStream(file); */
// Connect to Oracle
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "scott", "tiger");
con.setAutoCommit(false);
PreparedStatement ps = con.prepareStatement("insert into photos values(?,?,?)");
ps.setString(1, photoid);
ps.setString(2, phototitle);
// size must be converted to int otherwise it results in error
ps.setBinaryStream(3, file.getInputStream(), (int) file.getSize());
ps.executeUpdate();
con.commit();
con.close();
out.println("Proto Added Successfully. <p> <a href='listphotos'>List Photos </a>");
}
catch(Exception ex) {
out.println( "Error --> " + ex.getMessage());
}
}
}
In the above code I want to know functionality of DiskFileItemFactory, ServletFileUpload and FileItem classes.
please help me.Thank you.
View Answers
Related Tutorials/Questions & Answers:
Image uploadingImage uploading Hi,can anyone explain the following code.
The code related to
uploading an
image file to oracle database using java servlet.
CODE
import java.io.*;
import java.io.IOException;
import
Advertisements
Image uploading in FTP ServerImage uploading in FTP Server I want to upload images to a ftp server every 1 hour automatically using java..please help
change the name of the image after uploading the imagechange the name of the
image after
uploading the image my form consists of a textbox and
uploading the image.after
uploading the
image i want to change the name of the
image with the content of the textbox before saving
uploading image in the formuploading image in the form Hi All,
I am working to build a form like railway registration form which accepts user id and password and
image for authentication.
And i want all users should be able to see the
image once
Uploading an image - JSP-ServletUploading an image I am doing a jsp project. In this
uploading an
image is a part. For that i had done a coding for
uploading... and
uploading is done by different jsp coding. I don't know how to code for file size
Uploading Multiple Image On Server?Uploading Multiple
Image On Server? Hello sir,
I am stuck with a problem of
uploading multiple images on server.
i have done a code which works fine for
uploading single
image,but it doesn't work with
uploading multiple
Uploading image using jspUploading image using jsp how to upload
image using jsp. Already i tried, But that
image file does not read.
It returns only -1 without reading that
image file ...
I want know that solution using by u...
Thanks,
P.S.N.
struts image uploadingstruts
image uploading please let me know how to upload
image in database using struts ..i have written form class and 'm hanging out in action class ....
form
FileUploadForm:
package com.action.form;
import
struts image uploadingstruts
image uploading please let me know how to upload
image in database using struts ..i have written form class and 'm hanging out in action class ....
form
FileUploadForm:
package com.action.form;
import
struts image uploadingstruts
image uploading please let me know how to upload
image in database using struts ..i have written form class and 'm hanging out in action class ....
form
FileUploadForm:
package com.action.form;
import
struts image uploadingstruts
image uploading please let me know how to upload
image in database using struts ..i have written form class and 'm hanging out in action class ....
form
FileUploadForm:
package com.action.form;
import
Uploading an image into the table - JSP-ServletUploading an
image into the table how to upload an
image... binary stream of given
image.
FileInputStream fis;
try {
// Load JDBC...");
// create a file object for
image by specifying full path of
image Problem in uploading image to to mysql databaseProblem in
uploading image to to mysql database Hi, need some help here, i have a program where a user can input name, city and upload
image. when a user click the submit button the name, city and the
image(Save as BLOB) must
Problem in uploading image to to mysql databaseProblem in
uploading image to to mysql database Hi, need some help here, i have a program where a user can input name, city and upload
image. when a user click the submit button the name, city and the
image(Save as BLOB) must
save the uploading image with user specified namesave the
uploading image with user specified name My form consists of a textbox and an upload
image with submit button.When i submit the form I want to save the uploaded
image in a folder with user specfied name
save the uploading image with user specified namesave the
uploading image with user specified name My form consists of a textbox and an upload
image with submit button.When i submit the form I want to save the uploaded
image in a folder with user specfied name
uploading of image showing exception when size increases.uploading of
image showing exception when size increases. Hi . I have a project in which the user can upload images. it works properly, but when the
image size increases to arnd 1 MB or more it shows exception. I am using tomcat
image uploading perminssion in server - JSP-Servletimage uploading perminssion in server thanks dear,
but i am working in Linux Ubuntu, how can i set the path in server.
my problem is i am not able to access the folders wherever we are
uploading the files, we are not able
Need help in image uploading - JSP-ServletNeed help in
image uploading hii,
i have one doubt in
uploading an
image in jsp. I want to display
image from DB to my jsp page. For that i... to remote server..???
regards
Sreejith
Here is my code for
image uploading rename before uploadingrename before uploading I need to change (rename)the file name/
image name before
uploading it so that the file gets uploaded on server with this new name
Uploading filesUploading files Hi,
Please provide html code for my question.
I need to insert the browsed files temporarily to text area while attaching more than one files during mailing
photo uploadingphoto uploading i want the code upload the
image in oracle database
uploading a fileuploading a file When I am trying to upload a file to another system in lan at a location "http://192.168.12.5:8080/tomcat-docs/myapps",then it is giving the following error message "http://192.168.12.5:8080/tomcat-docs/myapps
uploading problemuploading problem i use glassfish server..
using netbeans for jsp...
i wnat to upload a file to a folder 'doc' and insert corresponding
data... curresponding
image files start new
upload");
%><
imageimage how to add the
image in servlet code
ImageImage how to insert
image in xsl without using xml. the
image was displayed in pdf..Please help me
ImageImage how to insert
image in xsl without using xml. the
image was displayed in pdf..Please help me
ImageImage how to insert
image in xsl without using xml. the
image was displayed in pdf..Please help me
image image Dear every body please help me how to add and retrive
image and video into oracle 11g using jsp
Uploading File on ServerUploading File on Server Hello,
Can someone explain or suggest example. How do i
uploading files on the FTP Server.
Thanks
Uploading a Software and storing in the databaseUploading a Software and storing in the database I want to upload....
The coding present in the site for
uploading and storing in the database... me with the code for
uploading software of bigger size
File Uploading NotificationFile
Uploading Notification I am
uploading files in my application and i want to know how can i know or be notified when file is uploaded. is there any file
uploading event there which can tell me that process is going
Uploading website
Uploading your website
Uploading Web Site
After developing the web... command.
7) After
uploading you web site, don't forgot to test it. User
uploading and copying filesuploading and copying files how can i upload and copy one file based on the given inputs and copy it from one directory to another
uploading file to tomcat serveruploading file to tomcat server please tell me how to upload a file to the URL "http://192.168.12.7:8000/tomcat-docs/" ?
thanks
FORM Tag Correctly for Uploading Files.FORM Tag Correctly for
Uploading Files. How To Write the FORM Tag Correctly for
Uploading Files?
Hi friends,
When you clicks the submit... from the browser to the Web server. This transferring (
uploading) process
File uploading - AjaxFile uploading hi friends,
how to
uploading the file by using "AJAX".Please send the complete source code for this application
where u want to store the file
Can u specify
Uploading Employee Profile with image Uploading Employee Profile with
image
... a
image in the employee file.
In
this example we are going to tell you how we can upload
image in a file by using
Jsp and how they will get stored
Uploading Employee Profile with image Uploading Employee Profile with
image
... a
image in the employee file.
In
this example we are going to tell you how we can upload
image in a file by using
Jsp and how they will get stored
Uploading a file using UploadBeanUploading a file using UploadBean Dear sir,
In my project i have to upload the file and use the same file for getting a values from that uploaded .xls file.I used UploadBean for
uploading .For the first time when i
query related to uploading filequery related to
uploading file hello friends
i am doing my project in servlet and i want to upload a file and store file in local hard drive... to save the
uploading time and date in database.
please help me it is urgent