0

我不知道我的代码有什么问题,它显示了这个错误:它之前执行过,但现在我不知道为什么它没有运行..我无法理解这个类文件异常,因为我添加了servelet-api。 jar 文件也在我的库中

 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.

我的代码:

<%@ page import="java.util.List" %>
   <%@ page import="java.util.Iterator" %>
   <%@ page import="java.io.File" %>
   <%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
   <%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
   <%@ page import="org.apache.commons.fileupload.*"%>
<%
 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") >= 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("\\") >= 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");
   %>
4

1 回答 1

0

问题出在这行代码中 -

javax.servlet.ServletException:java.lang.NoClassDefFoundError:javax/servlet/ServletInputStream

看看下面的链接

javax.servlet.ServletException:java.lang.NoClassDefFoundError:javax/servlet/ServletInputStream

并检查您的 Classpath 以查看您是否添加/删除了任何新 jar 或不正确的 jar。

于 2012-12-08T04:08:04.250 回答