Now when I use dthmlxVault in my project,I can not upload file successfully,now i whill describe the question next:
in my xhtml page i used these script:
the code in UploadHandler.java is:
public void UploadHandler(){
System.out.print(“in the method of UploadHandler()!!!”);
String uploadFolder = “c:\upload\”;
HttpServletResponse response = FacesContextUtil.getResponse();
HttpServletRequest request = FacesContextUtil.getRequest();
HttpSession session = FacesContextUtil.getSession();
// Check that we have a file upload request
boolean isMultipart = FileUpload.isMultipartContent(request);
if (!isMultipart) {
PrintWriter out;
try {
out = response.getWriter();
out.println (“Use multipart form to upload a file!”);
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
String fileId = request.getParameter("sessionId").toString().trim();
// Create a new file upload handler
FileItemFactory factory = new ProgressMonitorFileItemFactory(request, fileId);
ServletFileUpload upload = new ServletFileUpload(factory);
// Parse the request
List items;
try {
items = upload.parseRequest(request);
// Process the uploaded items
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
if (item.isFormField()) {
//processFormField
} else {
//processUploadedFile
String fieldName = item.getFieldName();
String fileName = item.getName();
int i2 = fileName.lastIndexOf("\\");
if(i2>-1) fileName = fileName.substring(i2+1);
File dirs = new File(uploadFolder);
//dirs.mkdirs();
File uploadedFile = new File(dirs,fileName);
item.write(uploadedFile);
session.removeAttribute("FileUpload.Progress."+fileId);
session.setAttribute("FileUpload.Progress."+fileId,"-1");
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
FacesContextUtil.getFacesContext().responseComplete();
}
so i found the problem after debugging is that: when the program entered the method of UploadHandler the size of List items is 0 and the while (iter.hasNext()) ) is false,but I do not why and how to resolve the problems ,so i hope you can give me some help.I must tell you that my project is a JSF project!thanks!!