2016-09-06 7 views
1

私はtype="file"type="submit"のフォームを持っていますが、今は選択したファイルをサーバーに送信する必要があります私は自分のフォームを送信するたびに、私は言って巨大なApacheのエラーを取得することです:リクエストにマルチパート/フォームデータまたはマルチパート/混合ストリームのApacheエラーが含まれていません

HTTPステータス500 - org.apache.tomcat.util.http.fileupload.FileUploadBase $ InvalidContentTypeException:リクエストがマルチパートが含まれていません/フォームデータまたはマルチパート/混合ストリームの場合、コンテンツタイプヘッダはapplication/x-www-form-urlencodedです。

He私はあなたに追加する必要がありますapache v9.0 and java EE 8

答えて

0

を使用しています

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    PrintWriter out = response.getWriter(); 

    String description = request.getParameter("description"); // Retrieves <input type="text" name="description"> 
    Part filePart = request.getPart("file"); // Retrieves <input type="file" name="file"> 
    String fileName = Paths.get(filePart.getSubmittedFileName()).getFileName().toString(); // MSIE fix. 
    InputStream fileContent = filePart.getInputStream(); 
    File file = new File("D:\\image123.jpg"); 
    file.createNewFile(); 
    OutputStream stream = new DataOutputStream(new FileOutputStream(file)); 
    IOUtils.copy(fileContent,stream); 
} 

宣言にenctype = "multipart/form-データを形成:

<form method="POST" action="../propicuploader"> 
      <div class="browsephoto_div"> 
       <label class="takeapicture_btn"> 
        <input type="file" accept=".png, .gif, .jpeg, .jpg" id="imagetoupload" enctype="multipart/form-data" onchange="document.getElementById('myImg').src = window.URL.createObjectURL(this.files[0])" required/> 
        <span>Browse</span> 
       </label> 
      </div> 
      <div class="ProfilePicsubmit_div"> 
       <input type="submit" class="Profilpicsubmit_btn" value="Next"/> 
      </div> 
     </form> 

私のサーバーサイドスクリプト:私のクライアント側のスクリプトで再「 例: <form method="POST" action="../propicuploader" enctype="multipart/form-data" >

場合あなたは詳細を知りたい:What does enctype='multipart/form-data' mean?

関連する問題