Dear friends, I am writing a program for uploading a file onto my webserver with JSP. I use JSP, Tomcat, Apache2, MySQL. I use this program : http://jakarta.apache.org/commons/fileupload/ . I choose the version 1.1. But it does not run properly as I expect (HTTP Status 500). Please tell me where the mistake. Thank you very much in advance. ----- // This is my 'ps.jsp' : <body> <table cellpadding="0" cellspacing="0" border="1" align="center"> <form enctype="multipart/form-data" action="http://localhost:8080/penguin-teknologi/penguin-teaches/cgiupload.jsp" method="post" name="myform"> <tr><td align="justify"><font style="Comic Sans MS, Arial">Silahkan pilih file yg akan diupload.</font></td></tr> <tr><td><input type="text" name="nama"></td></tr> <tr><td align="justify"><input type="file" name="soalnya"></td></tr> <tr><td align="justify"><input type="submit" value="Kirim"><input type="reset"></td></tr> </form> </table> </body> ----- // This is my 'cgiupload.jsp' <%@ page import="org.apache.commons.fileupload.*, java.util.List, java.io.File, java.util.Iterator" %> <% boolean isMultipart = FileUpload.isMultipartContent(request); if(!isMultipart){ request.setAttribute("msg", "Request was not multipart!"); request.getRequestDispatcher("msg.jsp").forward(request, response); return; } DiskFileUpload upload = new DiskFileUpload(); List items = upload.parseRequest(request); Iterator itr = items.iterator(); while(itr.hasNext()){ FileItem item = (FileItem) itr.next(); if(item.isFormField()) { String fieldName = item.getFieldName(); if(fieldName.equals("name")) request.setAttribute("msg", "Thank You: " + item.getString()); } else { File fullFile = new File(item.getName()); File savedFile = new File(getServletContext().getRealPath("/"), fullFile.getName()); item.write(savedFile); } } request.getRequestDispatcher("msg.jsp").forward(request, response); %> ----- // This is my 'msg.jsp' : <body> <% String msg = (String)request.getAttribute("msg"); if(msg != null) out.println("<font size=+1>Buseettt<br>" + msg + "</font><br/>"); %> Click <a href="../../../../../Apache%20Group/Apache2/htdocs/p-tek/penguin-teaches/ps.jsp">here</a> to go to the upload page. </body> ----- 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: org/apache/commons/io/output/DeferredFileOutputStream org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510) 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.penguin_002dteaches.cgiupload_jsp._jspService(cgiupload_jsp.java:80) 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.penguin_002dteaches.cgiupload_jsp._jspService(cgiupload_jsp.java:57) 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.16 logs. -------------------------------------------------------------------------------- Apache Tomcat/5.5.16
root cause
java.lang.NoClassDefFoundError:
org/apache/commons/io/output/DeferredFileOutputStream
Hi the above line is most probably the cause for your problem. Please open the fileupload.jar in Konqueror and search for this class if it is not there grab a different version and try it again. I would advice you to do it with a smaller file in the beginning. Regards, George __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
root cause
java.lang.NoClassDefFoundError:
org/apache/commons/io/output/DeferredFileOutputStream
Hi the above line is most probably the cause for your problem. Please open the fileupload.jar in Konqueror and search for this class if it is not there grab a different version and try it again.
I would advice you to do it with a smaller file in the beginning.
Regards, George
If you find that the class is there make sure that the lib is in your app's lib folder so that Tomcat can compile the jsp. george __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
Hallo George, Firstly thank you for your respond. I edit my 'cgiupload.jsp' code but it still does not run as expected. This one is wrong : " org/apache/commons/io/output/DeferredFileOutputStream " because DeferredFileOutputStream is placed here: " org/apache/commons/fileupload/DeferredFileOutputStream ". But why does 'import="org.apache.commons.fileupload.* still produces mistake? I can not understand. Please tell me where is the mistake. Thank you very much ==== //my new 'cgiupload.jsp'. <%@ page import="java.util.List, java.io.File, java.util.Iterator, org.apache.commons.fileupload.DeferredFileOutputStream, org.apache.commons.fileupload.DiskFileUpload, org.apache.commons.fileupload.FileUploadBase, org.apache.commons.fileupload.FileUpload, org.apache.commons.fileupload.FileItem" %> <% boolean isMultipart = FileUpload.isMultipartContent(request); if(!isMultipart){ request.setAttribute("msg", "Request was not multipart!"); request.getRequestDispatcher("msg.jsp").forward(request, response); return; } DiskFileUpload upload = new DiskFileUpload(); List items = upload.parseRequest(request); Iterator itr = items.iterator(); while(itr.hasNext()){ FileItem item = (FileItem) itr.next(); if(item.isFormField()) { String fieldName = item.getFieldName(); if(fieldName.equals("name")) request.setAttribute("msg", "Thank You: " + item.getString()); } else { File fullFile = new File(item.getName()); File savedFile = new File(getServletContext().getRealPath("/"), fullFile.getName()); item.write(savedFile); } } request.getRequestDispatcher("msg.jsp").forward(request, response); %> === //The new error message: 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: Unable to compile class for JSP Generated servlet error: Only a type can be imported. org.apache.commons.fileupload.DeferredFileOutputStream resolves to a package org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510) 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 org.apache.jasper.JasperException: Unable to compile class for JSP Generated servlet error: Only a type can be imported. org.apache.commons.fileupload.DeferredFileOutputStream resolves to a package org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84) org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328) org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:413) org.apache.jasper.compiler.Compiler.compile(Compiler.java:297) org.apache.jasper.compiler.Compiler.compile(Compiler.java:276) org.apache.jasper.compiler.Compiler.compile(Compiler.java:264) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:303) 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.16 logs. -------------------------------------------------------------------------------- Apache Tomcat/5.5.16 ----- Original Message ----- From: "George Stoianov" <gstoyanoff@yahoo.com> To: <> Sent: Thursday, March 30, 2006 10:38 PM Subject: Re: [suse-programming-e] FileUpload.1.1 and http status 500
root cause
java.lang.NoClassDefFoundError:
org/apache/commons/io/output/DeferredFileOutputStream
Hi the above line is most probably the cause for your problem. Please open the fileupload.jar in Konqueror and search for this class if it is not there grab a different version and try it again.
I would advice you to do it with a smaller file in the beginning.
Regards, George
__________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
-- To unsubscribe, email: suse-programming-e-unsubscribe@suse.com For additional commands, email: suse-programming-e-help@suse.com Archives can be found at: http://lists.suse.com/archive/suse-programming-e
Hi Patrick,
This one is wrong : "
org/apache/commons/io/output/DeferredFileOutputStream
" because DeferredFileOutputStream is placed here: "
org/apache/commons/fileupload/DeferredFileOutputStream Hum that seems like the wrong package altogether you can try 2 things one is get the commons IO library and put it in the lib folder but do not do an import as you did down here, as you will need to specify full path names to use 2 classes with the same name, it seems that fileupload is actually using commons-io as I did not see an explicit call in your code for the file Tomcat is complaining about. So get the commons io remove the imports and try it again. If it does not work get fileupload 1.0 as opposed to 1.1 and try with that as the older library may not use that call and it may work.
".
But why does 'import="org.apache.commons.fileupload.* still produces mistake? I can not understand.
Please tell me where is the mistake.
Thank you very much ==== //my new 'cgiupload.jsp'. <%@ page import="java.util.List, java.io.File, java.util.Iterator,
org.apache.commons.fileupload.DeferredFileOutputStream,
org.apache.commons.fileupload.DiskFileUpload, org.apache.commons.fileupload.FileUploadBase, org.apache.commons.fileupload.FileUpload, org.apache.commons.fileupload.FileItem" %>
Remove the explicit import for DeferredFileOutputStream.
Generated servlet error: Only a type can be imported.
org.apache.commons.fileupload.DeferredFileOutputStream
resolves to a package
This error means that Tomcat thinks this is a package not a class check you libs. regards, george __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
participants (2)
-
George Stoianov
-
Patrix Linux