如何将文本值与多个文件上传表单一起传递
我有一个文件上传表单,可以上传多个文件。 现在我已经硬编码了要存储上传文件的文件夹名称。
但我需要的是在上传时表单还应该发送将在服务器上创建的文件夹名称来存储上传的文件。
这是我的表单
<form action="uploadprocess.jsp" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input name="file" type="file" id="file">
<input name="file" type="file" id="file">
<input name="foldername" type="hidden"> <!-- i will set folder name during run time -->
</form>
,当我使用 request.getParameter("foldername") 时,我得到 null
I am having one file upload form which uploads multiple files.
Right now I have hard coded the folder name in which the uploaded file is to be stored.
But what I need is at the time of upload the form should also send folder name which will be created on the server to store uploaded files.
This is my form
<form action="uploadprocess.jsp" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input name="file" type="file" id="file">
<input name="file" type="file" id="file">
<input name="foldername" type="hidden"> <!-- i will set folder name during run time -->
</form>
I am getting null when I use request.getParameter("foldername")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为
enctype="multipart/form-data"
。要从“multipart/form-data”表单中获取值,您需要使用MultipartRequest
。当您使用多部分表单时,您可以访问request
对象上的参数。请参阅:get-form-parameters-from-multipart -request 了解如何获取多部分请求中的参数。
或者试试这个:
com.oreilly.servlet.MultipartRequest
上调用getParameters()
Because of
enctype="multipart/form-data"
. To get value from a form of "multipart/form-data" you need to useMultipartRequest
.When you use multipart form you can access parameters onrequest
object.See this: get-form-parameters-from-multipart-request to know how to get parameter in multipart request.
Else try this:
getParameters()
oncom.oreilly.servlet.MultipartRequest