title: finding exception in uploading file in jsp
body: <p>i don't know what's wrong with my code ,it is showing this error:it was executing earlier but now i dn't know why it is not running.. i can't understand this classfileexception as i hv added servelet-api.jar file also in my lib</p>
  
  <pre><code> exception 
  
  org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream
      org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:534)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:442)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  
  
  root cause 
  
  javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:911)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:840)
      org.apache.jsp.upload_jsp._jspService(upload_jsp.java:151)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  
  
  root cause 
  
  java.lang.NoClassDefFoundError: javax/servlet/ServletInputStream
      org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:126)
      org.apache.jsp.upload_jsp._jspService(upload_jsp.java:101)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  
  
  note The full stack trace of the root cause is available in the Apache Tomcat/7.0.12 logs.
  </code></pre>
  
  <p>my code:</p>
  
  <pre><code>&lt;%@ page import="java.util.List" %&gt;
     &lt;%@ page import="java.util.Iterator" %&gt;
     &lt;%@ page import="java.io.File" %&gt;
     &lt;%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%&gt;
     &lt;%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%&gt;
     &lt;%@ page import="org.apache.commons.fileupload.*"%&gt;
  &lt;%
   File file ;
     int maxFileSize = 5000 * 1024;
     int maxMemSize = 5000 * 1024;
     ServletContext context = pageContext.getServletContext();
     String filePath = context.getInitParameter("file-upload");
  
     // Verify the content type
     String contentType = request.getContentType();
     if ((contentType.indexOf("multipart/form-data") &gt;= 0)) 
     {
  
        DiskFileItemFactory factory = new DiskFileItemFactory();
        // maximum size that will be stored in memory
        factory.setSizeThreshold(maxMemSize);
        // Location to save data that is larger than maxMemSize.
        factory.setRepository(new File("c:\\filesuploaded"));
  
        // Create a new file upload handler
        ServletFileUpload upload = new ServletFileUpload(factory);
        // maximum file size to be uploaded.
        upload.setSizeMax( maxFileSize );
      try{ 
           // Parse the request to get file items.
           List fileItems = upload.parseRequest(request);
  
           // Process the uploaded file items
           Iterator i = fileItems.iterator();
  
  
           while ( i.hasNext () ) 
           {
              FileItem fi = (FileItem)i.next();
             if ( !fi.isFormField () )    
              {
              // Get the uploaded file parameters
              String fieldName = fi.getFieldName();
              String fileName = fi.getName();
              boolean isInMemory = fi.isInMemory();
              long sizeInBytes = fi.getSize();
              // Write the file
              if( fileName.lastIndexOf("\\") &gt;= 0 )
              {
                  file = new File( filePath + 
                  fileName.substring( fileName.lastIndexOf("\\"))) ;
              }
              else
              {
                  file = new File( filePath + 
                  fileName.substring(fileName.lastIndexOf("\\")+1)) ;
              }
  
              fi.write( file ) ;
              out.println("Uploaded Filename: " + filePath + 
              fileName );
              }
           }
        }
  
        catch(Exception ex) {
           System.out.println(ex);
        }
     }
      else
          System.out.println("no file");
     %&gt;
  </code></pre>