【问题标题】:enctype="multipart/form-data" is not supported to send simple text? [duplicate]enctype="multipart/form-data" 不支持发送简单文本? [复制]
【发布时间】:2015-04-30 03:30:02
【问题描述】:

当我在 jsp 表单中使用 enctype="multipart/form-data" 时,简单的文本、日期、数字不会发送到 servlet,它显示空值,当我删除 enctype="multipart/form-data" 然后表单工作好吧……为什么……怎么……

我的jsp代码....

    <form method="post" action="<%=request.getContextPath()%>/ProfileServlet" enctype="multipart/form-data" >
                                                        <div class="form-group">
                                                            <label class="control-label">First Name</label>
                                                            <input type="text" placeholder="John" name="txtfname" class="form-control"/>
                                                        </div>
                                                        <div class="form-group">
                                                            <label class="control-label">Last Name</label>
                                                            <input type="text" placeholder="Doe" name="txtlname" class="form-control"/>
                                                        </div>
                                                        <div class="form-group">
                                                            <label class="control-label">Birth day</label>
                                                            <input type="date" placeholder="Doe" name="txtdate" class="form-control"/>
                                                        </div>
照片

它使用jsp中的enctype在servlet中显示空值,否则它工作正常.....

【问题讨论】:

  • 你为什么要使用 multipart/form-data?通常,当您的任何输入类型是文件类型时使用此选项
  • 是的,我发送个人资料照片
  • 你在用弹簧吗?你声明了一个多部分处理程序吗?

标签: java html forms jsp servlets


【解决方案1】:

虽然使用enctype="multipart/form-data" 表单字段不能用作请求的参数,但您将始终将request.getParameter(name); 设为空。它们包含在流中。您可以使用 Apache Commons Fileupload 上传带有其他表单字段数据的文件。为了使用 Apache Commons FileUpload,您需要在您的 webapp 的 /WEB-INF/lib 中有以下文件:

1.) commons-fileupload.jar

2.) commons-io.jar

例如

if (item.isFormField()) {
    String name = item.getFieldName();
    String value = item.getString();
}

看看http://commons.apache.org/proper/commons-fileupload//using.html

【讨论】:

  • 谢谢……兄弟……我明白了……
  • 是的,您的帮助已全部用于我
猜你喜欢
  • 2013-07-30
  • 1970-01-01
  • 1970-01-01
  • 2021-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多