This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Below is my servlet code, where I can save the file locally at the given location. My problem is , I have a text box on JSP , where user enters company name in the text box. When I was trying to get the value of text box, it is throwing null.
I have searched on forums...and it says if ENCTYPE="multipart/form-data ..we cannot get the form field values.. Anyone can help on a way to get my form field.
FileItemFactory factory = new DiskFileItemFactory(); boolean isMultipart = FileUpload.isMultipartContent(request); ServletFileUpload upload = new ServletFileUpload(factory); List /* FileItem */ items = upload.parseRequest(request); Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); String formFieldValue = request.getParameter("fileName"); /////It shows NULL value. if (item.isFormField()) { System.out.println("It is a field"); } else { System.out.println("its a file"); System.out.println(item.getName()); String name = item.getFieldName(); String value = item.getString(); File cfile=new File(item.getName());
File folder;
if(saveFile.endsWith("pdf")){ folder = new File("C:/upload/documents"); } else{ folder = new File("C:/upload/images"); } File tosave=new File(folder,cfile.getName());