Multiple image upload using JSP

Multiple image upload using JSP

I have written a code to upload the multiple images using jsp, but when I execute this code, it throws Corrupt form data: premature ending error.

Apache tomcat version : 8.0.9.0

Can anybody please help me to resolve this issue?

Html file

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <FORM action="upload_jsp.jsp" enctype="multipart/form-data" method="post">

   What files are you sending? <INPUT type="file" name="file[]" multiple >
   <INPUT type="submit" value="Send"> <INPUT type="reset">
 </FORM>


</body>
</html>

JSP Code

> <%@ page import="java.sql.*" %> <%@
> page
> import="org.apache.commons.fileupload.*"%>
> <%@ page
> import="org.apache.commons.io.output.*"%>
> <%@ page
> import="org.apache.commons.fileupload.servlet.*"%>
> <%@ page
> import="org.apache.commons.fileupload.disk.*"%>
> 
> <%@ page
> import="org.apache.commons.io.FileUtils"
> %>
> 
> <%@ page import="java.io.*"%> <%@ page
> import="java.util.*"%> <%@ page
> import="javax.servlet.*"%>
> 
> <%@ page
> import="com.oreilly.servlet.multipart.MultipartParser"%>
> <%@ page
> import="com.oreilly.servlet.multipart.Part"%>
> <%@ page
> import="com.oreilly.servlet.multipart.FilePart"%>
> 
> <%  
>     String fileSavePath_upload_dir;
>     String fileSavePath_upload_user_dir;
>     String fileSavePath_sec_storage_user_dir;
>     String user_name = "abc1234567890";
>     String sec_storage_images_path = "C:\\Users\\gur29175\\Desktop";
>     String UPLOAD_DIRECTORY = "Uploads";    
>     String user_image_dir = user_name;
> 
>     File sourceFile;
>     File destinationFile;    
>     String resp = "";    
>     int i = 1;
>     int counter=0;    
> 
>     fileSavePath_upload_dir = getServletContext().getRealPath("/") +
> File.separator +
> UPLOAD_DIRECTORY;/*save uploaded files
> to a 'Upload' directory in the web
> app*/
>     fileSavePath_upload_user_dir = fileSavePath_upload_dir +
> File.separator + user_image_dir;
>     fileSavePath_sec_storage_user_dir = sec_storage_images_path + File.separator + user_name;
> 
>     if (!(new File(fileSavePath_upload_dir)).exists())
> 
>     {
>         (new File(fileSavePath_upload_dir)).mkdir();
> // creates the directory if it does
> not exist        
>     }
> 
>     if (!(new File(fileSavePath_upload_user_dir)).exists())
> 
>     {
>         (new File(fileSavePath_upload_user_dir)).mkdir();
> // creates the directory if it does
> not exist        
>     }
> 
>     if (!(new File(sec_storage_images_path)).exists())
> 
>     {
>         (new File(sec_storage_images_path)).mkdir();
> // creates the directory if it does
> not exist        
>     }
> 
>     if (!(new File(fileSavePath_sec_storage_user_dir)).exists())
> 
>     {
>         (new File(fileSavePath_sec_storage_user_dir)).mkdir();
> // creates the directory if it does
> not exist        
>     }
> 
>     resp += "<br>Here is information about uploaded files.<br>";
>     try
>     {
>         MultipartParser parser = new MultipartParser(request,
> 1024*1024*1024);  /* file limit size
> of 1GB*/
>         Part _part;
>         while ((_part = parser.readNextPart()) != null) 
>         {
>             if (_part.isFile()) 
>             {
>                 FilePart fPart = (FilePart) _part;  // get some info
> about the file
>                 String name = fPart.getFileName();
> 
>                 if (null != name) 
>                 {
>                     long fileSize = fPart.writeTo(new
> File(fileSavePath_upload_user_dir));
>                     resp += i++ + ". " + fPart.getFilePath() + "[" + fileSize / 1024 + " KB]<br>";
> 
>                     sourceFile = new File(fileSavePath_upload_user_dir+"/"+user_name+"_"+counter+".png");
>                     counter++;
>                 }                 else 
>                 {
>                     resp = "<br>The user did not upload a file for this
> part.";
>                 }
>             }
>         }// end while 
>                 }
>     catch (java.io.IOException ioe)
>     {
>         out.println(ioe);
>         resp = ioe.getMessage();
>     }     %>
View Answers









Related Tutorials/Questions & Answers:
Multiple image upload using JSP
Multiple image upload using JSP  I have written a code to upload the multiple images using jsp, but when I execute this code, it throws Corrupt form...; fileSavePath_upload_user_dir = fileSavePath_upload_dir + > File.separator + user_image
upload image using JSP Hibernate
upload image using JSP Hibernate  sir, I want to take image from user and save to database(MYSQL) using Hibernate and JSP Thanks in advance
Advertisements
Image upload in mysql database using jsp servlet
Image upload in mysql database using jsp servlet  Hello, I need code to insert image in mysql database, I have seen the code which is already in your portal but it is not inserting image into database it save in the folder
insert name city and upload image in database using mysql and jsp
insert name city and upload image in database using mysql and jsp   insert name city and upload image in database using mysql and jsp
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... to upload the multiple images in struts Total images storing folder in project using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... to upload the multiple images in struts Total images storing folder in project using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... to upload the multiple images in struts Total images storing folder in project using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... to upload the multiple images in struts Total images storing folder in project using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... to upload the multiple images in struts Total images storing folder in project using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... to upload the multiple images in struts Total images storing folder in project using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... to upload the multiple images in struts Total images storing folder in project using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... to upload the multiple images in struts Total images storing folder in project using this jsp,but i want to CollegeAction class and CollegeForm class how to do
How to upload multiple images in java(struts) using jsp?
How to upload multiple images in java(struts) using jsp?  I have jsp... to upload the multiple images in struts Total images storing folder in project using this jsp,but i want to CollegeAction class and CollegeForm class how to do
Multiple upload - JSP-Servlet
Multiple upload  Hello everyone and Deepak i am using jsp and mysql I am using the program published on roseindia.net of Multiple upload and i am facing an error as given below please help and reply soon this is my 8th
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 upload an image from a jsp page to a mysql database table using jsp
how to upload an image from a jsp page to a mysql database table using jsp  how to upload an image from a jsp page to a mysql database table using jspstrong text
Upload Image and save in database using jsp-servlet mvc
Upload Image and save in database using jsp-servlet mvc  Here is my code.. In jsp ... <form name=frm method="post" action="Device"> <table> <tr><TD ><B>Upload Image</B><
Upload Image and save in database using jsp-servlet mvc
Upload Image and save in database using jsp-servlet mvc  Here is my code.. In jsp ... <form name=frm method="post" action="Device"> <table> <tr><TD ><B>Upload Image</B><
Image upload file - JSP-Servlet
Image upload file  I want a code for image upload jsp or servlet.  Hi friend, For image upload jsp or servlet visit to : http://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml http
image upload with jsp from form
image upload with jsp from form  hi i used the code specified in your following post http://www.roseindia.net/answers/viewqa/JSP-Servlet/9749-image...) org.apache.jsp.upload_jsp._jspService(upload_jsp.java:85
file upload using JSP
file upload using JSP  I have created a form to upload a file in a html page, now i want to get the path of the file in a jsp page so what code...="java" %> <HTML> <HEAD><TITLE>Display file upload form
Uploading image using jsp
Uploading image using jsp  how to upload image using jsp. Already i... that image file ... I want know that solution using by u... Thanks, P.S.N.   Here is a jsp code that upload image and display it on the browser. 1
how to upload multiple files in jsp and saving the path in database and the file in folder
how to upload multiple files in jsp and saving the path in database and the file in folder  how to upload multiple files in jsp and saving the path in database and the file in folder I have created a form for the upload of files
Email to multiple recipients using jsp
Email to multiple recipients using jsp  Hi sir, Am a doing a project,in that i need to send email to multiple user at a time,the to address should enter manually its not not be written in code using jsp. Regards, Santhosh
Email to multiple recipients using jsp
Email to multiple recipients using jsp  Hi sir, Am a doing a project,in that i need to send email to multiple user at a time,the to address should enter manually its not not be written in code using jsp. Regards, Santhosh
Uploading Multiple Files Using Jsp
to understand how you can upload multiple files by using the Jsp. We should avoid... Uploading Multiple Files Using Jsp  ... a file. In this example we are going to tell you how we can upload multiple files
Storing Multiple image in sql using java
Storing Multiple image in sql using java  Hi, How to store and retrieve a multiple image in sql using java but already i have created sql table if i want to insert a image while runtime execution. Can anyone tell me solution
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
Upload and Download multiple files
Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc... using jsp with sqlserver ,can you please provide a proper coding for it and also
upload csv to mysql db using jsp upload
upload csv to mysql db using jsp upload  Hello all, Please give me the code to uplad .csv from jsp page and insert values into MySQl db. I have a table with 8 cloumns.(MDN--varchar(30),Otafdate date,crt varchar(30),dmdn
image upload&download using jsp - JSP-Servlet
image upload&download using jsp  can any one help in writing jsp for upload and download of images from database..  Hi Friend, Please visit the following links: http://www.roseindia.net/jsp/fileupload.shtml http
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database
How to upload files to server using JSP/Servlet?
How to upload files to server using JSP/Servlet?  How to upload files to server using JSP/Servlet
how to upload and download images using buttons in jsp?
how to upload and download images using buttons in jsp?  how to upload and download images using buttons in jsp
download image using url in jsp
download image using url in jsp  how to download image using url in jsp
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
How to upload file using JSP?
How to upload file using JSP?   Hi all, I m the beginner in JSP, I want to upload file on server in specific folder.   1)page.jsp... file upload form to the user</TITLE></HEAD> <
how to upload image from jsp to mssql
how to upload image from jsp to mssql  hi there!!, i'm using jsp and servlet to upload images to the database. however i have difficulty in uploading database. hope u can help in my database: i have imagetbl that contain image
how to upload image from jsp to mssql
how to upload image from jsp to mssql  hi there!!, i'm using jsp and servlet to upload images to the database. however i have difficulty in uploading database. hope u can help in my database: i have imagetbl that contain image
Uploading Multiple Files Using Jsp
to understand how you can upload multiple files by using the Jsp. We should avoid... Uploading Multiple Files Using Jsp  ... a file. In this example we are going to tell you how we can upload multiple files
Image name,image path into database and image into folder using jsp
Image name,image path into database and image into folder using jsp  How to insert image path and image name into oracle database and image into folder using jsp
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
image upload and stored in database - JSP-Servlet
image upload and stored in database  How can i upload a image and store that image in a database  Hi Friend, Try the following code: 1)page.jsp: Display file upload form to the user UPLOAD
passing the form values with image upload - JSP-Servlet
passing the form values with image upload  Hii . I want to get the solution for passing values with an image uploading form. I cant access the request values from the fields rather than image . I want to know how can cut
upload a file and write it in JSP using servlet
upload a file and write it in JSP using servlet  Hello, I'm facing a problem here. I want to upload a file through abc.jsp and write the contents of file using a servlet in xyz.jsp. It is supposed to be a excel file which
image upload in webapp/upload folder
image upload in webapp/upload folder  sir i want to store upload image in my project directory WebApp/Upload_image/ pls send the jsp servlet code when i upload the image one error found "system cannot found the specified path
upload image
upload image  I want to upload image from user using Jdbc connectivity and servlets and Html pages. I tried code but getting error using multi parts,so please send the code
how to fetch image from mysql using jsp
how to fetch image from mysql using jsp  how to fetch image from mysql using jsp
How i upload file and save that record in database using JSP?
How i upload file and save that record in database using JSP?  Hi All, I m the beginner in JSP and I want to upload the file and store that file... like Emp name, Emp id, city, address and one employee profile image(upload

Ads