[英]Multi-part form not working
對於多部分表格,我得到一種奇怪的行為。 我有一個簡單的HTML多部分表單,並且正在使用Apache Commons庫提取字段和文件。 但是,由於某種原因,servlet代碼ServletFileUpload.isMultipartContent(request)返回false。 以下是HTML和Servlet代碼。 有人可以讓我知道我要去哪里嗎?
這是HTML文件代碼。
<body>
<form method="post" action="http://localhost:8080/myapp/handler" enctype="multi-part/form-data">
<input type="text" name="exp_name">
<input type="file" name="exp_image_upload_0">
<br />
<button type="submit">Submit</button>
<button class="btn">Cancel</button>
</form>
</body>
這是Servlet代碼
/** Common method called by doGet and doPost methods **/
private void executeRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
boolean isMultiPart = ServletFileUpload.isMultipartContent(request);
System.out.println("Content Type : " + request.getContentType());
System.out.println("Name : " + request.getParameter("exp_name"));
if (isMultiPart)
System.out.println(">>>> IS MULTIPART");
else
System.out.println(">>>> IS NOT MULTIPART");
}
對於此代碼,我始終會打印“ IS NOT MULTIPART”。 我確定有某些地方我缺少或做錯了,但是無法確切地確定是什么? 請幫助。
如下更改表單標簽中的enctype屬性:
enctype="multipart/form-data"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.