{"id":4018,"date":"2014-03-30T07:13:03","date_gmt":"2014-03-30T07:13:03","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/file-upload-problem-using-apache-commans-file-upload-api-in-jsp-servlet-collection-of-common-programming-errors\/"},"modified":"2014-03-30T07:13:03","modified_gmt":"2014-03-30T07:13:03","slug":"file-upload-problem-using-apache-commans-file-upload-api-in-jsp-servlet-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/file-upload-problem-using-apache-commans-file-upload-api-in-jsp-servlet-collection-of-common-programming-errors\/","title":{"rendered":"File upload problem using Apache commans File upload API in JSP\/Servlet-Collection of common programming errors"},"content":{"rendered":"<p>im trying to upload a file using org.apache.commons.fileupload. but i dont no, what mistake i have made im getting the following error in my servlet. please any one help me on this..this is the error im getting.<\/p>\n<pre><code>     javax.servlet.ServletException: Servlet execution threw an exception\n\n\n root cause \n\n java.lang.NoClassDefFoundError: org\/apache\/commons\/io\/output\/DeferredFileOutputStream\norg.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:199)\norg.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:361)\norg.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)\nupload1.doPost(upload1.java:34)\njavax.servlet.http.HttpServlet.service(HttpServlet.java:637)\n     javax.servlet.http.HttpServlet.service(HttpServlet.java:717)\n<\/code><\/pre>\n<p>this is my servlet code<\/p>\n<pre><code>   if (ServletFileUpload.isMultipartContent(req)) {\n\n         \/\/ Create a factory for disk-based file items\n         FileItemFactory factory = new DiskFileItemFactory();\n\n         \/\/ Create a new file upload handler\n         ServletFileUpload upload = new ServletFileUpload(factory);\n\n         \/\/ Parse the request\n         try {\n             List items = upload.parseRequest(req);\n             for (FileItem item : items) {\n                 \/\/ process only file upload - discard other form item types\n                 if (item.isFormField()) continue;\n\n                 String fileName = item.getName();\n                 \/\/ get only the file name not whole path\n                 if (fileName != null) {\n                    \/\/ fileName = FilenameUtils. getName(fileName);\n                 }\n\n\n             }\n         } catch (Exception e) {\n             res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,\n                     \"An error occurred while creating the file : \" + e.getMessage());\n         }\n\n     } else {\n         res.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE,\n                         \"Request contents type is not supported by the servlet.\");\n     }\n<\/code><\/pre>\n<p>and form<\/p>\n<pre><code>          \n<\/code><\/pre>\n<p>thank u<\/p>\n","protected":false},"excerpt":{"rendered":"<p>im trying to upload a file using org.apache.commons.fileupload. but i dont no, what mistake i have made im getting the following error in my servlet. please any one help me on this..this is the error im getting. javax.servlet.ServletException: Servlet execution threw an exception root cause java.lang.NoClassDefFoundError: org\/apache\/commons\/io\/output\/DeferredFileOutputStream org.apache.commons.fileupload.disk.DiskFileItemFactory.createItem(DiskFileItemFactory.java:199) org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:361) org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126) upload1.doPost(upload1.java:34) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) this is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4018","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4018"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4018\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}