File Uploading Problem

Ads
 

File Uploading Problem

I have a file uploading code but it create problem

$(document).ready(function(){
$('#upload').click(function(){

var fileName=$('#myFile').val();
alert(fileName);
$.ajax({
  type: 'POST',
  dataType: 'json',
  url: 'myServlet',
  data:{path:fileName},
  contentType:'multipart/form-data'
  success: function(msg){
    //alert( "Data Saved: " + msg );
    document.getElementById('filenameSeq').innerHTML='<div style="width:200px; color: black;background-color: white;"><ul><li>'+msg+'&nbsp&nbsp;<a href="#####"><b>X</b></a></li></ul></div>';
  }
});
});

});

but when we run it the code it gives the problem

org.apache.commons.fileupload.FileUploadException: the request was rejected because no multipart boundary was found

and my server side code is

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try{ 
            System.out.println("------------------------------------------");
            FileUpload fup=new FileUpload(); 
            boolean isMultipart = FileUpload.isMultipartContent(request); 
            // Create a new file upload handler 
            System.out.println(isMultipart); 
            DiskFileUpload upload = new DiskFileUpload(); 

            // Parse the request 
            List /* FileItem */ items = (List) upload.parseRequest(request); 

            Iterator iter = (Iterator) ((java.util.List) items).iterator(); 
            while (((java.util.Iterator) iter).hasNext()) { 

            FileItem item = (FileItem) ((java.util.Iterator) iter).next(); 

            if (item.isFormField()) { 
            System.out.println("its a field"); 
            } else { 
            System.out.println("its a file"); 
            System.out.println(item.getName()); 
            File cfile=new File(item.getName()); 
            File tosave=new File(getServletContext().getRealPath("/Web-INF/manu/"),cfile.getName()); 
            System.out.println(tosave);
            item.write(tosave); 
            } 
            } 

            }catch(Exception e){System.out.println(e);} 
    }               

this code run perfectly well when i send action without jquery

if u have any solution then share it

View Answers

Ads









Related Tutorials/Questions & Answers:
File Uploading Problem
File Uploading Problem  I have a file uploading code but it create problem $(document).ready(function(){ $('#upload').click(function(){ var... it gives the problem org.apache.commons.fileupload.FileUploadException
File Uploading Problem
File Uploading Problem  I have a file uploading code but it create problem $(document).ready(function(){ $('#upload').click(function(){ var... it gives the problem org.apache.commons.fileupload.FileUploadException
Advertisements
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 about file into database lib. i use navicat Mysql ... i use this code... <
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 audio file iphone
uploading audio file iphone  uploading audio file iphone
Problem in uploading java application
Problem in uploading java application  I have uploaded my java application (folder created under webapps) using Filezilla FtpClient.Application... this problem
file uploading
file uploading  How to upload music files onto the server and save the file information to the mysql database fetch and play the music files on a display page without download thus streaming the files
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
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 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
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 and file name and path in oracle database.with name file name and path i also want
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database  Hi, need some help... have no problem in saving the image in the folder, my problem is it can't save...="java" %> <HTML> <HEAD><TITLE>Display file upload form
Problem in uploading image to to mysql database
Problem in uploading image to to mysql database  Hi, need some help... have no problem in saving the image in the folder, my problem is it can't save... the file To Upload:</b></td> <td><INPUT NAME="file" TYPE="file
uploading a text file into a database
uploading a text file into a database  how to upload a text file... { static File file; public static void main(String[] args) throws Exception { JLabel label=new JLabel("Choose File
file uploading using jsp
file uploading using jsp  below file uploading code has one error... = " + formDataLength); //String file = new String(dataBytes); //out.println("FileContents:" + file +""); byte[] line = new byte[128]; if (totalBytesRead
Uploading and download pdf or .txt file.
Uploading and download pdf or .txt file.  I want admin user to upload pdf file into database and the users can download those pdf format from database
Uploading a single file by using JSp
Uploading a single file by using JSp  u have said about submit button..but in program u have not used submit button..and where file will be stored..where should we specify the output folder name..   Visit Here
uploading a file - JSP-Interview Questions
uploading a file   uploading a file and storing in database using...; public File currentDir; public DropTarget target; JButton addButton...,BorderLayout.SOUTH); currentDir = new File(System.getProperty("user.dir")); } public
Uploading a single file by using JSp
Uploading a single file by using JSp  u have said about submit button..but in program u have not used submit button..and where file will be stored...;b>Choose the file To Upload:</b></td> <td><INPUT 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... , but upload file to database ] ... Pls help
Getting path name of uploading file in struts 2.1.8
Getting path name of uploading file in struts 2.1.8  In my question I used struts 2.8.1 instead of 2.1.8. Sorry
Problem reading word file
Problem reading word file  Deepak you provide me code for extarcting equation from a word file and also to write in a word file.But when I again want to read preveously created word file(created by your code) it gives an error
Getting path name of uploading file in struts 2.8.1
Getting path name of uploading file in struts 2.8.1  Hai! I am using struts 2.8.1. I want to upload file into database with the path name. How can I can get the original path name of the file in struts 2.8.1? It only display
uploading a file at another system in lan using jsp
uploading a file at another system in lan using jsp  Thanks for the code at "http://www.roseindia.net/jsp/fileupload/Sinleupload.xhtml.shtml... to save or upload the file at another system in lan at location "http
Uploading file in servlet from a html form
Uploading file in servlet from a html form  Sir, I want to upload a picture from my html file and save it to my database as BLOB,but what JAR should i use for this purpose i am really confused about.And also is it possible to do
application context file problem
application context file problem  how to configure junit application context file with struts........? it is not finding sessionfactory method
retrieving excel data when file uploading
retrieving excel data when file uploading  <%@page import...); } } %> when i gave full path name i got excel data but when file uploading not getting the excel data
Problem in getting file path in js
Problem in getting file path in js  hi, I am using ofbiz framework , How i can get the file path in javascript for input type = "file" and i am using only firefox not other browser. so please help me it is very important for me
struts jar file problem
struts jar file problem  hi.. I'm using struts-core-1.3.9.jar. it works well if am using ma application with internet but it shows me an error while initializing ActionServlet when i disconnected to Internet The error stack trace
FTP file copy problem? - Java Beginners
FTP file copy problem?  Hi, Can any one tell me how to set file... using for uploading files to server. [code] File f = new File(localfilePath...-net-1.4.1.jar to copy files from local system to server. Eg: local file name ?test.doc
problem while reading .csv file
problem while reading .csv file  I have a problem here..... i am reading a .csv extention file which has some value....but the problem is der is an amount column which contains , in between (eg) 3,899.00 which inturns creates

Ads