hiii everyone... i am doing my project on netbeans ide , creating a post web server for database. i am having some problem in file uploading .. i am sending data from advanced rest client along with the file ... bt its sending 500 error... its not accepting request.getParameter("data i am giving from rest client").... my code is....
else if (action.equalsIgnoreCase("fileUpload")) {
String userId =request.getParameter("userId");
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart) {
} else {
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
List items = null;
try {
items = upload.parseRequest(request);
} catch (FileUploadException e) {
e.printStackTrace();
}
Iterator itr = items.iterator();
while (itr.hasNext()) {
FileItem item = (FileItem) itr.next();
if (item.isFormField()) {
}
else {
try {
String itemName = item.getName();
System.out.println("FILE PATH " + getServletContext().getRealPath("/"));
File savedFile = new File(getServletContext().getRealPath("/") + "uploadedFiles/" + itemName);
item.write(savedFile);
String str = "build-web-uploadedFiles-" + itemName + "";
dao.addFile(userId, str);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire