繁体   English   中英

多部分表格不起作用

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM