Topic: 用commons.fileupload上传文件,出现错误,各位帮帮忙,急~(请看内容) |
Print this page |
1.用commons.fileupload上传文件,出现错误,各位帮帮忙,急~(请看内容) | Copy to clipboard |
Posted by: miaomiaoga Posted on: 2006-03-14 02:51 错误信息说错在16行,16行就是:List fileItems = fu.parseRequest(request); 是request出现什么问题的了?不明白。 我用的是TOMCAT,已经把commons-fileupload-1.1.jar放到Tomcat5.5\common\lib里和项目里的WEB-INF\lib目录下了,还有什么没有做的吗? 整个运行环境应该是正常的,因为我有另外一个页面读取mysql的资料都正常的,估计不是配置的问题,是不是我还缺些什么东西呢? 请各位指示,谢谢。:) 错误信息如下: HTTP Status 500 - -------------------------------------------------------------------------------- type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: Exception in JSP: /up61.jsp:16 13: // 儲存的目錄 14: //fu.setRepositoryPath(application.getRealPath("/") + "temp/"); 15: fu.setRepositoryPath("c:\\TEMP"); 16: List fileItems = fu.parseRequest(request); 17: 18: Iterator itr = fileItems.iterator(); 19: while(itr.hasNext()) { Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) root cause javax.servlet.ServletException: org/apache/commons/io/output/DeferredFileOutputStream org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791) org.apache.jsp.up61_jsp._jspService(org.apache.jsp.up61_jsp:79) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) root cause java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream org.apache.commons.fileupload.DefaultFileItemFactory.createItem(DefaultFileItemFactory.java:102) org.apache.commons.fileupload.FileUploadBase.createItem(FileUploadBase.java:500) org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:367) org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:268) org.apache.jsp.up61_jsp._jspService(org.apache.jsp.up61_jsp:62) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:332) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) note The full stack trace of the root cause is available in the Apache Tomcat/5.5.15 logs. -------------------------------------------------------------------------------- Apache Tomcat/5.5.15 源代码如下: upload.html: <form action="save.jsp" enctype="multipart/form-data" method="POST"> input your name: <input type="text" name="name"> <br> select the file: <input type="file" name="file"> <br> <input type="submit" value="submit"> </form> save.jsp: <%@ page import="java.util.List"%> <%@ page import="java.util.Iterator"%> <%@ page import="java.io.File"%> <%@ page import="org.apache.commons.fileupload.DiskFileUpload"%> <%@ page import="org.apache.commons.fileupload.FileItem"%> <%@page contentType="text/html;charset=GBK"%> <% DiskFileUpload fu = new DiskFileUpload(); // 使用的記憶體容量,超過先寫入暫存檔 fu.setSizeThreshold(4096); // 最大上傳檔案容量 fu.setSizeMax(1000000); // 儲存的目錄 //fu.setRepositoryPath(application.getRealPath("/") + "temp/"); fu.setRepositoryPath("c:\\TEMP"); List fileItems = fu.parseRequest(request); //****这是第16行****// Iterator itr = fileItems.iterator(); while(itr.hasNext()) { FileItem fi = (FileItem)itr.next(); out.println("\nNAME: "+fi.getName()); out.println("SIZE: "+fi.getSize()); File fNew= new File(application.getRealPath("/"), fi.getName()); fi.write(fNew); } %> (缩略图,点击图片链接看原图) |
2.Re:用commons.fileupload上传文件,出现错误,各位帮帮忙,急~(请看内容) [Re: miaomiaoga] | Copy to clipboard |
Posted by: zcjl Posted on: 2006-03-14 09:00 java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream 我想不用再翻译了吧? 检查一下commons-io.jar这个包是否存在,并正确配置到classpath中 |
3.Re:用commons.fileupload上传文件,出现错误,各位帮帮忙,急~(请看内容) [Re: miaomiaoga] | Copy to clipboard |
Posted by: miaomiaoga Posted on: 2006-03-18 21:37 其实还是不懂.但我把文件COPY到TOMCAT的根目录去就可以正常运行了.估计是配置或者是其它的问题.刚开始用JSP和TOMCAT.~~没办法...再努力学习才行... |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |