Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 331
  • Last Modified:

jakarta comman fileupload errors...

I'm using jakarta Fileupload pakage....

i'm getting this exception...

javax.servlet.ServletException: org/apache/commons/io/output/DeferredFileOutputStream
      org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
      org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
      org.apache.jsp.ProcessFileUpload_jsp._jspService(ProcessFileUpload_jsp.java:97)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      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.ProcessFileUpload_jsp._jspService(ProcessFileUpload_jsp.java:65)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)



Please help out on how to resolve this...
0
jagadeesh_motamarri
Asked:
jagadeesh_motamarri
  • 7
  • 2
  • 2
2 Solutions
 
CEHJCommented:
You need the commons IO classes in your classpath
0
 
jagadeesh_motamarriAuthor Commented:
Now different error comes....

HTTP Status 404 - E:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\TrackingSystem\f:\capstone course\scope_1_0.doc (The filename, directory name, or volume label syntax is incorrect)

--------------------------------------------------------------------------------

type Status report

message E:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\TrackingSystem\f:\capstone course\scope_1_0.doc (The filename, directory name, or volume label syntax is incorrect)

description The requested resource (E:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\TrackingSystem\f:\capstone course\scope_1_0.doc (The filename, directory name, or volume label syntax is incorrect)) is not available.



But the file is available on the desktop ...


0
 
jagadeesh_motamarriAuthor Commented:
Here is the sample code that i'm using....

UploadFiles.html

<HTML>
  <HEAD>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"/>
    <TITLE>File Upload Page</TITLE>
  </HEAD>
  <BODY>Upload Files
    <FORM name="filesForm" action="ProcessFileUpload.jsp"
    method="post" enctype="multipart/form-data">
        File 1:<input type="file" name="file1"/><br/>
        File 2:<input type="file" name="file2"/><br/>
        File 3:<input type="file" name="file3"/><br/>
        <input type="submit" name="Submit" value="Upload Files"/>
    </FORM>
  </BODY>
</HTML>



and the ProcessFileUpload.jsp is ...


<%@ page contentType="text/html;charset=windows-1252"%>
<%@ page import="org.apache.commons.fileupload.DiskFileUpload"%>
<%@ page import="org.apache.commons.fileupload.FileItem"%>
<%@ page import="org.apache.commons.io.*"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="java.io.File"%>
html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Process File Upload</title>
</head>
<%
        System.out.println("Content Type ="+request.getContentType());

        DiskFileUpload fu = new DiskFileUpload();
        // If file size exceeds, a FileUploadException will be thrown
        fu.setSizeMax(10000000);

        List fileItems = fu.parseRequest(request);
        Iterator itr = fileItems.iterator();

        while(itr.hasNext()) {
          FileItem fi = (FileItem)itr.next();

          //Check if not form field so as to only handle the file inputs
          //else condition handles the submit button input
          if(!fi.isFormField()) {
            System.out.println("\nNAME: "+fi.getName());
            System.out.println("SIZE: "+fi.getSize());
            //System.out.println(fi.getOutputStream().toString());
            File fNew= new File(application.getRealPath("/"), fi.getName());

            System.out.println(fNew.getAbsolutePath());
            fi.write(fNew);
          }
          else {
            System.out.println("Field ="+fi.getFieldName());
          }
        }
%>
<body>
Upload Successful!!
</body>
</html>


i don't have a clue .....
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jagadeesh_motamarriAuthor Commented:
i'm actually using this code to upload files to one of the tomcat directories....what changes do i need to make......even i can post this as another question...
0
 
objectsCommented:
>             File fNew= new File(application.getRealPath("/"), fi.getName());

thats inccorect, getName() returns the complete path
should be more like:

            File fNew= new File(application.getRealPath("/"), new File(fi.getName()).getName());
0
 
jagadeesh_motamarriAuthor Commented:
but now...where is the file uploaded to...
0
 
jagadeesh_motamarriAuthor Commented:
i got it...thankz...
0
 
jagadeesh_motamarriAuthor Commented:
added to this how can i create a directory of my own name and store there...its creating in the root directory of my project folder itslef...

an someone help me...
0
 
objectsCommented:
File dir = new File(application.getRealPath("/"), "nameOfDirectory");
if (!dir.exists()) dir.mkdir();

File fNew= new File(dir, new File(fi.getName()).getName());
0
 
CEHJCommented:
:-)
0
 
jagadeesh_motamarriAuthor Commented:
since i thought i should post a new question...i declared the points...


now i'm able to create directories and store files into them...but still i'm getting this error...
HTTP Status 404 - E:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\TrackingSystem\nameOfDirectory (Access is denied)

--------------------------------------------------------------------------------

type Status report

message E:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\TrackingSystem\nameOfDirectory (Access is denied)

description The requested resource (E:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\TrackingSystem\nameOfDirectory (Access is denied)) is not available.



...............and ofcourse "nameOfDirectory " is the newly created file and it does contain the file that i'm uploading
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 7
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now