我正在尝试使用Parts从多部分表单中获取值,而不使用DiskFileItemFactory。 在这段代码中,我能够处理文件,但是不确定如何获取传递的其他非文件值。
failed assertion `For color attachment 0, the renderPipelineState pixelFormat must be MTLPixelFormatInvalid, as no texture is set.'
}
答案 0 :(得分:0)
请在下面找到:
@WebServlet(name = "ImageHandler", urlPatterns = {"/ImageHandler"})
@MultipartConfig(maxFileSize = 100 * 1024 * 1024) // 100MB max
public class ImageHandler extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String name = request.getParameter("name");
out.println("<br>name: " + name);
// Create a new file upload handler
InputStream inputStream = null;
// obtains the upload file part in this multipart request
Part filePart = request.getPart("file");
if (filePart != null) {
// prints out some information for debugging
out.println("<br>getName: " + filePart.getName());
out.println("<br>getSize: " + filePart.getSize());
out.println("<br>getContentType: " + filePart.getContentType());
// obtains input stream of the upload file
//inputStream = filePart.getInputStream();
}
}
}
HTML格式:
<form action="ImageHandler" method="post" enctype="multipart/form-data" role="form">
Name: <input maxlength="100" type="text" name="name" class="form-control" placeholder="" />
<br>
file: <input type="file" id="files" name="file" />
<br>
<input type="submit" value="submit">
</form>