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

Ads









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
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><
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
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
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
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
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
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
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
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
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
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
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> <
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
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
how to fetch image from mysql using jsp
how to fetch image from mysql using jsp  how to fetch image from mysql using jsp
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
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
How I Upload File and Store that file name in Database using JSP
How I Upload File and Store that file name in Database using JSP  Hi All, I m the beginner in JSP and I want to upload the file and store that file... form like Emp name, Emp id, city, address and one employee profile image(upload
jsp upload file to server
jsp upload file to server  How to create and upload file to server in JSP?   Find the given example that explains how to upload single and multiple file on server using JSP
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
Multiple files upload code using spring mvc 2.0 with xml configuration without using annotations
Multiple files upload code using spring mvc 2.0 with xml configuration without using annotations  how to write code to attach multiple files and upload using spring mvc 2.o with xml configuration with out annotations? please
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
<img src=""> using retrieve image from database using jsp
using retrieve image from database using jsp  how to <img src="" > tag using retrieve image from database and display in jsp
Read code from excel sheet and upload into database using JSP
Read code from excel sheet and upload into database using JSP  I want to upload data to database from an excel worksheet using jsp ...Please help
how do i upload a file by using servlet or jsp?
how do i upload a file by using servlet or jsp?  hi plz tell me the write java code
upload image to database
upload image to database  i am try to upload image to MySql database using netbeans. when jsp execute it return no error. but also data does inserted in database. i am using blob datatype and preopared statement
upload image
upload image  how can i retreive image from mysql using jsp in netbeans.The image type is varchar with size 200.the image is uploaded succesfully.The... is stored in mysql... 2.retreive.jsp //the image is retreived using the id

Ads