Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I tried to use the file upload using Apache Commons but the following exception thrown

org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is null

My html code is

<form  name="inp" action="upload.jsp"  method="get" onsubmit="return valid();" enctype="multipart/form-data">
<table align="center" cellspacing="2">

  <tr><td><font size="5" color="#E41B17">Select File</font> </td>
<td><input type="file" name="infile"></td>
</tr>
<tr><td><font size="5" color="#E41B17">Target File Name</font></td>
<td><input type="text" size="20" name="filename"></input></td>
</tr>
<tr></tr>
<tr><td colspan="2" align="center"><input type=submit value="Upload"  ></td></tr>
</table>
<br></br>
<center>
<a href="index.html"><font color="#E41B17">HOME</font></a>
</center>
</form>

My JSP code is

   <% 
   String user = (String)session.getAttribute("uname");
   String f = request.getParameter("filename");

   DiskFileUpload upload = new DiskFileUpload();         
   boolean isMultipart=upload.isMultipartContent(request);


   upload.setSizeMax(1048576);     
   List items = upload.parseRequest(request);  
   FileItem  file = (FileItem) items.get(0); 

   String source = file.getName();
      String delim="\\";
   String str="";
   File propfile=new File("C:\\eclipse_practise\\fileupload\\WebContent\\path.properties");

   BufferedInputStream propbuf=new BufferedInputStream(new FileInputStream(propfile));

   Properties path=new Properties();

   path.load(propbuf);

   String serverlocation=path.getProperty("Server_path");

   session.setAttribute("storelocation",serverlocation);

   StringTokenizer st = new StringTokenizer(source,delim);

   while(st.hasMoreTokens())
   {                        
       str=st.nextToken();
   }

   FileItem  name = (FileItem) items.get(1);

   String  target = name.getString();

   File outfile = new File(serverlocation+target);

    file.write(outfile); 

      session.setAttribute("filename",target);

   %>
share|improve this question
up vote 8 down vote accepted

The form has to be method="POST"

share|improve this answer
2  
please clarify why the method had to "POST" – Karthik.m Sep 22 '09 at 8:31
1  
Because that's the way that multipart forms work. – skaffman Sep 22 '09 at 8:57
1  
Because when u click the submit button the form will collect all the data include file(Image) also.and packed it and send it to the server in http request.. – Ramesh J Mar 6 '13 at 10:31
1  
In that case it u declare the method="get" , the data is visible in at hyper link.. ie, url?param1=value$param2=value.. And this http request have a limit in length. so some data is missing while request is travll. so we use method="post" In this post, the form collect all the information and make it as a bundle and send it to the server .... so finally the form must declare as "post" type while deling with any media files... – Ramesh J Mar 6 '13 at 10:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.