Multiple image upload using JSP

 
 

Share on Google+Share on Google+

sumit vedi
Multiple image upload using JSP
0 Answer(s)      2 years and a month ago
Posted in : JSP-Servlet

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();
>     }     %>
Ads
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
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
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
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
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
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
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
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 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
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

Ads

 
Advertisement null

Ads