请帮忙。我几乎看到每个论坛都是徒劳的。我不明白为什么hasNext()返回false?
public class FileUploadServ extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (isMultipart) {
JOptionPane.showMessageDialog(null,"is multipart");
ServletFileUpload upload = new ServletFileUpload();
try {
FileItemIterator itr = upload.getItemIterator(request);
boolean c=itr.hasNext(); // why does this return false
JOptionPane.showMessageDialog(null,"hasNext value:"+c);
while (c=itr.hasNext()){
FileItemStream item = itr.next();
if (item.isFormField()) {
}
else {
String path= getServletContext().getRealPath("/");
if (FileUpload.processFile(path, item))
response.getWriter().println("Upload Successful");
else
response.getWriter().println("Upload Failed!");
}
}
//JOptionPane.showMessageDialog(null,"out of while hasNext value:"+c);
} catch (FileUploadException fue) {
//fue.printStackTrace();
JOptionPane.showMessageDialog(null,"error!:"+ fue.getMessage());
}
}
}
}