Hi I have created a HTML form to upload multiple files through a servlet. I am using Tomcat 3.2 version and I have placed the commons-fileupload-1.2.1.jar and commons-io-1.4.jar in C:\Tomcat\lib directory. The servlet compiles but at run time generate exception of java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletReques. I also copied the whole lib folder and put it into C:\Tomcat\webapps\root\web-inf folder but still the same status. I am totally stuck here.
HTML Code from where I am accessing the servlet is
<form action="/servlet/FileUploadDemoServlet" method="post" enctype="multipart/form-data">
I have placed the servlet in C:\Tomcat\webapps\root\web-inf\classes folder.
Servlet code is as follows:
Any help in this regard please.import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.fileupload.FileItemFactory; import org.apache.commons.fileupload.FileUploadException; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import java.io.*; import java.util.*; import java.io.IOException; import java.io.File; import java.util.List; import java.util.Iterator; public class FileUploadDemoServlet extends HttpServlet { private static final long serialVersionUID = -3208409086358916855L; protected void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException { boolean isMultipart = ServletFileUpload.isMultipartContent(request); if (isMultipart) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); try { List items = upload.parseRequest(request); Iterator iterator = items.iterator(); while (iterator.hasNext()) { FileItem item = (FileItem) iterator.next(); if (!item.isFormField()) { String fileName = item.getName(); String root = getServletContext().getRealPath("/"); File path = new File(root + "check/uploads"); if (!path.exists()) { boolean status = path.mkdirs(); } File uploadedFile = new File(path + "/" + fileName); System.out.println(uploadedFile.getAbsolutePath()); item.write(uploadedFile); } } } catch (FileUploadException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } }