2009-09-22 8 views
7

मैं अपाचे कॉमन्स का उपयोग कर फ़ाइल अपलोड उपयोग करने के लिए कोशिश की, लेकिन निम्नलिखित अपवाद उत्पन्न

org.apache.commons.fileupload.FileUploadBase $ InvalidContentTypeException: अनुरोध एक बहुखण्डीय/फार्म-डेटा या बहुखण्डीय/मिश्रित धारा शामिल नहीं है, सामग्री प्रकार शीर्ष लेख रिक्त है

मेरे एचटीएमएल कोड है

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

मेरे JSP कोड

है
<% 
    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); 

    %> 

उत्तर

11

रूप होने विधि = "पोस्ट" है

+2

कृपया स्पष्ट क्यों विधि करने के लिए "पोस्ट" –

+2

था क्योंकि इस तरह से है कि बहुखण्डीय रूपों काम है। – skaffman

+1

क्योंकि जब आप सबमिट बटन पर क्लिक करते हैं तो फॉर्म सभी डेटा एकत्र करेगा फ़ाइल (छवि) भी। और इसे पैक किया गया है और इसे http अनुरोध में सर्वर पर भेजता है .. –

संबंधित मुद्दे