1

JSP =.= PLEASE I NEED YOUR HELP FOR UPLOADING.

upload.jsp

<body> <form name="form1" id="form1" action="test" method="post" enctype="multipart/form-data"> <input type="hidden" name="hiddenfield1" value="ok"> Files to upload: <br/> <input type="file" size="50" name="file1"> <br/> <input type="file" size="50" name="file2"> <br/> <input type="file" size="50" name="file3"> <br/> <input type="submit" value="Upload"> </form> </body>


and this is my TestServlet package test;

public class TestServlet extends HttpServlet {

private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    out.println("Hello<br/>");

    boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
    if (!isMultipartContent) {
        out.println("You are not trying to upload<br/>");
        return;
    }
    out.println("You are trying to upload<br/>");

    FileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    try {
        List<FileItem> fields = upload.parseRequest(request);
        out.println("Number of fields: " + fields.size() + "<br/><br/>");
        Iterator<FileItem> it = fields.iterator();
        if (!it.hasNext()) {
            out.println("No fields found");
            return;
        }
        out.println("<table border=\"1\">");
        while (it.hasNext()) {
            out.println("<tr>");
            FileItem fileItem = it.next();
            boolean isFormField = fileItem.isFormField();
            if (isFormField) {
                out.println("<td>regular form field</td><td>FIELD NAME: " + fileItem.getFieldName() + 
                        "<br/>STRING: " + fileItem.getString()
                        );
                out.println("</td>");
            } else {
                out.println("<td>file form field</td><td>FIELD NAME: " + fileItem.getFieldName() +
                        "<br/>STRING: " + fileItem.getString() +
                        "<br/>NAME: " + fileItem.getName() +
                        "<br/>CONTENT TYPE: " + fileItem.getContentType() +
                        "<br/>SIZE (BYTES): " + fileItem.getSize() +
                        "<br/>TO STRING: " + fileItem.toString()
                        );
                out.println("</td>");
            }
            out.println("</tr>");
        }
        out.println("</table>");
    } catch (FileUploadException e) {
        e.printStackTrace();
    }
}

}

and my web.xml
Web XML IMAGE HERE

When I run and upload a file

I GOT THE ERROR!

Error Image Here

I REALLY NEED YOUR HELP!!

LateHatred
  • 11
  • 1

1 Answers1

0

Looking from the error screen shot link you have included.

It says

java.lang.NoClassDefFoundError: org/apache/commons/io/output/DeferredFileOutputStream

It seems that you are missing Apache Commons IO jar, commons-io.jar in you Classpath. Commons File Upload is dependent on it.

You can download that from Apache Commons Site

Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96