org.apache.jasper.JasperException:在第17行处理JSP页面/upload.jsp时发生异常

时间:2016-11-03 11:31:58

标签: java jsp tomcat file-upload

我正在使用Tomcat-7和JRE 1.8.X

ClassPath: C:\ Program Files \ Tomcat \ lib \ commons-fileupload-1.3.2.jar; C:\ Program Files \ Tomcat \ lib \ commons-io-2.5.jar; C:\ Program Files \ Tomcat \ lib \ servlet-api.jar;

Woking目录: C:\ Program Files \ Tomcat \ webapps \ src

尝试将照片从计算机上传到 C:\ Program Files \ Tomcat \ webapps \ src \ uplods \ username。

我的代码:\ uplaod.jsp

<%@ page import="org.apache.commons.fileupload.servlet.ServletFileUpload" %>
<%@ page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="java.util.*, java.io.*" %>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.util.List"%>
<%@ page import="java.io.File"%>
<%@ page contentType="text/html;charset=UTF-8" %>

<%
try
{
File savedFile=new File("x.txt");
String ImageFile="";
String itemName = "";
String uname=session.getAttribute("uname").toString();
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
if (!isMultipart)
 {%>
 <script>alert("Form enctype must be "multipart/form-data".");</script>
 <%}
else
 {
 FileItemFactory factory = new DiskFileItemFactory();
 ServletFileUpload upload = new ServletFileUpload(factory);
 List items = null;
  items = upload.parseRequest(request);
  Iterator itr = items.iterator();
    FileItem item = (FileItem) itr.next();
        try
            {
            itemName = item.getName();
            savedFile = new File(config.getServletContext().getRealPath("/")+"\\src\\"+"\\uploads\\"+"\\"+uname+"\\"+uname+".jpg");
            out.print(itemName);
            item.write(savedFile);
            }
        catch (Exception e){out.println("Error"+e.getMessage());}
  }
}
catch (Exception e){out.println(e.getMessage());}
response.sendRedirect("SignUpConfirmPage.htm");
%>

我收到如下错误消息:

ype Exception report

message javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:561)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:462)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

javax.servlet.ServletException: java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
    org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916)
    org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845)
    org.apache.jsp.upload_jsp._jspService(upload_jsp.java:147)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.NoClassDefFoundError: javax/servlet/http/HttpServletRequest
    org.apache.commons.fileupload.servlet.ServletFileUpload.isMultipartContent(ServletFileUpload.java:68)
    org.apache.jsp.upload_jsp._jspService(upload_jsp.java:106)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause

java.lang.ClassNotFoundException: javax.servlet.http.HttpServletRequest
    java.net.URLClassLoader.findClass(Unknown Source)
    java.lang.ClassLoader.loadClass(Unknown Source)
    java.lang.ClassLoader.loadClass(Unknown Source)
    org.apache.commons.fileupload.servlet.ServletFileUpload.isMultipartContent(ServletFileUpload.java:68)
    org.apache.jsp.upload_jsp._jspService(upload_jsp.java:106)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

请帮助我。

0 个答案:

没有答案