关于eclipse的servelet上传文件报错“status 500”问题

楼主在做servletupload的题目时,发现一个错误:

type Exception report

message Servlet execution threw an exception

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

exception

javax.servlet.ServletException: Servlet execution threw an exception
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:91)

root cause

java.lang.NoClassDefFoundError: org/apache/commons/io/IOUtils
	org.apache.commons.fileupload.util.Streams.copy(Streams.java:123)
	org.apache.commons.fileupload.util.Streams.copy(Streams.java:70)
	org.apache.commons.fileupload.MultipartStream.readBodyData(MultipartStream.java:593)
	org.apache.commons.fileupload.MultipartStream.discardBodyData(MultipartStream.java:617)
	org.apache.commons.fileupload.MultipartStream.skipPreamble(MultipartStream.java:634)
	org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:1023)
	org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.(FileUploadBase.java:1003)
	org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:310)
	org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:334)
	org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:115)
	com.UploadServlet.doPost(UploadServlet.java:72)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:91)

root cause

java.lang.ClassNotFoundException: org.apache.commons.io.IOUtils
	java.net.URLClassLoader.findClass(Unknown Source)
	java.lang.ClassLoader.loadClass(Unknown Source)
	java.lang.ClassLoader.loadClass(Unknown Source)
	org.apache.commons.fileupload.util.Streams.copy(Streams.java:123)
	org.apache.commons.fileupload.util.Streams.copy(Streams.java:70)
	org.apache.commons.fileupload.MultipartStream.readBodyData(MultipartStream.java:593)
	org.apache.commons.fileupload.MultipartStream.discardBodyData(MultipartStream.java:617)
	org.apache.commons.fileupload.MultipartStream.skipPreamble(MultipartStream.java:634)
	org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.findNextItem(FileUploadBase.java:1023)
	org.apache.commons.fileupload.FileUploadBase$FileItemIteratorImpl.(FileUploadBase.java:1003)
	org.apache.commons.fileupload.FileUploadBase.getItemIterator(FileUploadBase.java:310)
	org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:334)
	org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:115)
	com.UploadServlet.doPost(UploadServlet.java:72)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:91)

note The full stack trace of the root cause is available in the Apache Tomcat/8.0.0-RC1 logs.

错误提示是找不到ioClass,然而楼主在eclipse内导入了commons-upload,commons-io的包,但还是这样报错,后来在网上查了好久才理清头绪,本人用的是Tomcat 8.0,lib下面已经有了Commons-upload的包,单独添加这个外部包,eclipse不会报错,但是运行上传文件后会报 500的错误。

解决方法:1.下载commons-io包

                 2.将下载好的commons-io包放在Tomcat的lib下面

                 3.在工程内添加外部包时,选择apache-tomcat\lib目录下的包 ①之前存在的commons-fileupload包②刚刚自行拷入的commons-io的包

运行结果:关于eclipse的servelet上传文件报错“status 500”问题_第1张图片

你可能感兴趣的:(个人笔记)