我正在尝试获取由表单 enctype“multipart/form-data”发送的请求参数。我正在使用 apache commons 文件上传。
我的代码如下。
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = upload.parseRequest(req);
Iterator uploadIterator = items.iterator();
while(uploadIterator.hasNext()){
FileItem uploadedItem = (FileItem) uploadIterator.next();
if (uploadedItem.isFormField()){
if (uploadedItem.getFieldName().equals("name")){
name = uploadedItem.getString();
}
}else{
//Uploaded files comes here
}
表单的 HTML 代码为:
<form name="form" id="form" method="post" action="ServletIncluirEvento"
enctype="multipart/form-data">
... //Here comes a lot of inputs (I changed the name of the attribute because I am from Brazil and the names are in portuguese)
<select size="9" id="idOpcoesSelecionadas" name="opcoesSelecionadas" multiple style="width: 100%;">
<%
it = colecaoUsuarioSelecionado.iterator(); String name= "";
while (it.hasNext()) {
usuario = (Usuario) it.next();
name += usuario.getName() + "/"; %>
<option value="<%=usuario.getLogin()%>">
<%=usuario.getName()%>
</option>
<%
}
%></select>
<input type="hidden" value="<%=name%>" name="name" />
即便如此,参数也将变为空。
有人知道怎么解决吗?
先感谢您