Image uploading

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 uploading
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
uploading image in php - PHP
uploading image in php  I am looking for a PHP script to upload image into mysql database
Advertisements
Image uploading in FTP Server
Image 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 image
change 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 form
uploading 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-Servlet
Uploading 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 jsp
Uploading 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 uploading
struts 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 uploading
struts 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 uploading
struts 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 uploading
struts 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-Servlet
Uploading 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 database
Problem 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 database
Problem 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 name
save 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 name
save 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 a Profile with image[file] into a sql database
Uploading a Profile with image[file] into a sql database  I need to upload a file along with the some text into a database ......[ Similar to http://www.roseindia.net/jsp/jspfileupload/employeeuploadprofile_image.shtml
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-Servlet
image 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
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  Thanks deepak following my... to writing image file in this path.. in multipartRequest. if u have any other uploading script please help me.. thanks   Hi, Plz give
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. but in server it is showing following error
image uploading perminssion in server - JSP-Servlet
image uploading perminssion in server  dear friend... following is my uploading code and i want to save some records....... while submitting time i am getting following error.................. HTTP
Need help in image uploading - JSP-Servlet
Need 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
error in uploading image from jsp to oracle 10g database
error in uploading image from jsp to oracle 10g database  ... try to insert into the image into the database i got the above error please advice how to get rid of error   JSP upload image in Mysql database
Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP - JSP-Servlet
. Is it not possible to use a image instead of normal html Browse button for uploading files...Using a image for Browse button instead of normal html Browse button for Uploading files from a JSP  I am using the following code snippet
rename before uploading
rename 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 files
Uploading 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 uploading
photo uploading  i want the code upload the image in oracle database
uploading a file
uploading 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 problem
uploading 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"); %><
uploading audio file iphone
uploading audio file iphone  uploading audio file iphone
image
image  how to add the image in servlet code
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
Image
Image  how to insert image in xsl without using xml. the image was displayed in pdf..Please help me
uploading and reading the excel daa
uploading and reading the excel daa  uploading the excel file not getting the data of the excel
image
image   Dear every body please help me how to add and retrive image and video into oracle 11g using jsp
Uploading File on Server
Uploading 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 database
Uploading 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 Notification
File 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 files
uploading 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 server
uploading 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 - Ajax
File 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 UploadBean
Uploading 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 file
query 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

Ads