![](/img/trans.png)
[英]the request doesn't contain a multipart/form-data or multipart/mixed stream apache error
[英]how to fix the request doesn't contain a multipart/form-data or multipart/mixed stream apache error
我有一個表單,其中我有一個type="file"
和一個type="submit"
,現在我需要將所選文件發送到服務器,但問題是,每當我提交表單時,我都會收到一個巨大的apache錯誤說:
HTTP狀態500 - org.apache.tomcat.util.http.fileupload.FileUploadBase $ InvalidContentTypeException:請求不包含multipart / form-data或multipart / mixed流,內容類型標題為application / x-www-form- urlencoded的
這是我的客戶端腳本:
<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>
我的服務器端腳本:
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);
}
我正在使用apache v9.0 and java EE 8
提前致謝:)
在表單中使用enctype =“multipart / form-data”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.