Apache 公共资源 ->文件上传-> DiskFileUpload无法解析
<%@ page import="org.apache.commons.fileupload.*" %> //一些代码.... DiskFileUpload fu = new DiskFileUpload();
我正在尝试使用apache commons函数DiskFileUpload,但由于找不到fileupload.jar而出现异常。我查看了与此论坛中类似问题相关的其他回复,人们建议将该文件添加到 WEB-INF/lib 中,我尝试了它,但它对我不起作用。
也许我把它放在错误的位置? 我的jsp路径是:apache-tomcat-6.0.29/webapps/ROOT/ClockAdmin/upload.jsp WEB-INF 是:apache-tomcat-6.0.29/webapps/WEB-INF/commons-fileupload-1.2.2.jar 库/ 我查看了其他帖子,但仍然不起作用: Apache 公共资源 ->文件上传-> parseRequest() 错误
我得到了以下异常:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 36 in the jsp file: /ClockAdmin/uploader2.jsp
DiskFileUpload cannot be resolved to a type
33: System.out.println( "CONTENT-LENGHT" + request.getContentLength());
34: System.out.println("session id = " + session.getId());
35:
36: DiskFileUpload fu = new DiskFileUpload();
37: // maximum size before a FileUploadException will be thrown
38: fu.setSizeMax(5000000);
39: // maximum size that will be stored in memory
An error occurred at line: 36 in the jsp file: /ClockAdmin/uploader2.jsp
DiskFileUpload cannot be resolved to a type
33: System.out.println( "CONTENT-LENGHT" + request.getContentLength());
34: System.out.println("session id = " + session.getId());
35:
36: DiskFileUpload fu = new DiskFileUpload();
37: // maximum size before a FileUploadException will be thrown
38: fu.setSizeMax(5000000);
39: // maximum size that will be stored in memory
An error occurred at line: 48 in the jsp file: /ClockAdmin/uploader2.jsp
FileItem cannot be resolved to a type
45: Iterator item = fileItems.iterator();
46: while(item.hasNext())
47: {
48: FileItem fi = (FileItem) item.next();
49: if(fi.isFormField())
50: {
51: continue;
An error occurred at line: 48 in the jsp file: /ClockAdmin/uploader2.jsp
FileItem cannot be resolved to a type
45: Iterator item = fileItems.iterator();
46: while(item.hasNext())
47: {
48: FileItem fi = (FileItem) item.next();
49: if(fi.isFormField())
50: {
51: continue;
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
<%@ page import="org.apache.commons.fileupload.*" %>
//some code....
DiskFileUpload fu = new DiskFileUpload();
I am trying to use the apache commons function DiskFileUpload, but it got an exception because fileupload.jar cannot be find. I look at other responses related to the similar problem in this forum and people suggested to add the file in WEB-INF/lib, and I try it but it is not working for me.
Maybe I put it in a wrong location?
My jsp path is:apache-tomcat-6.0.29/webapps/ROOT/ClockAdmin/upload.jsp
and the WEB-INF is:apache-tomcat-6.0.29/webapps/WEB-INF/commons-fileupload-1.2.2.jar
lib/
I look at other post but it is still not working:
Apache commons -> File Upload -> parseRequest() error
And I got the following exception:
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 36 in the jsp file: /ClockAdmin/uploader2.jsp
DiskFileUpload cannot be resolved to a type
33: System.out.println( "CONTENT-LENGHT" + request.getContentLength());
34: System.out.println("session id = " + session.getId());
35:
36: DiskFileUpload fu = new DiskFileUpload();
37: // maximum size before a FileUploadException will be thrown
38: fu.setSizeMax(5000000);
39: // maximum size that will be stored in memory
An error occurred at line: 36 in the jsp file: /ClockAdmin/uploader2.jsp
DiskFileUpload cannot be resolved to a type
33: System.out.println( "CONTENT-LENGHT" + request.getContentLength());
34: System.out.println("session id = " + session.getId());
35:
36: DiskFileUpload fu = new DiskFileUpload();
37: // maximum size before a FileUploadException will be thrown
38: fu.setSizeMax(5000000);
39: // maximum size that will be stored in memory
An error occurred at line: 48 in the jsp file: /ClockAdmin/uploader2.jsp
FileItem cannot be resolved to a type
45: Iterator item = fileItems.iterator();
46: while(item.hasNext())
47: {
48: FileItem fi = (FileItem) item.next();
49: if(fi.isFormField())
50: {
51: continue;
An error occurred at line: 48 in the jsp file: /ClockAdmin/uploader2.jsp
FileItem cannot be resolved to a type
45: Iterator item = fileItems.iterator();
46: while(item.hasNext())
47: {
48: FileItem fi = (FileItem) item.next();
49: if(fi.isFormField())
50: {
51: continue;
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将 JAR 放入
/WEB-INF/lib
文件夹中,而不是/WEB-INF
中。You need to drop JARs in
/WEB-INF/lib
folder, not in/WEB-INF
.我必须通过退回 Tomcat 服务器来手动部署 WAR 文件。这解压了 WAR,并且当服务器重新启动时,它没有抛出任何异常。我只能想象 Tomcat 设置中的配置错误,无法正确关闭并重新打开清单。
I had to manually deploy the WAR file by bouncing the Tomcat server. This unpacked the WAR and when the server started back up, it did not throw any exceptions. I can only imagine that I have a misconfiguration in the Tomcat setup to permit the manifest to be properly closed and reopened.