Multiple image upload using JSP

Ads
 

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
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 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
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
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
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
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
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
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
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
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
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

Ads