在 gwt Web 应用程序中。我必须发送一个文件和一些附加的参数。
在服务器端
try {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
if (item.isFormField()) {
String fieldName=item.getFieldName();
String fieldValue = Streams.asString(item.openStream());
System.out.println(" chk " +fieldName +" = "+ fieldValue);
} else {
stream = item.openStream();
fileName = item.getName();
mimetype = item.getContentType();
int c;
while ((c = stream.read()) != -1) {
System.out.print((char) c);
}
}
}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
System.out.println("out of try");
ByteArrayOutputStream output = new ByteArrayOutputStream();
int nRead;
while ((nRead = stream.read(buffer, 0, buffer.length)) != -1) {
System.out.println("lenth111" +nRead);
output.write(buffer, 0, nRead);
}
System.out.println("lenth" +nRead);
output.flush();
使用此代码,我可以读取流。并且还在控制台上打印了“out of try”
最后在while ((nRead = stream.read(buffer, 0, buffer.length)) != -1)
网上我得到了一个警告
警告:/UploadFileServlet:org.apache.commons.fileupload.FileItemStream$ItemSkippedException。
如何解决这个问题呢。??