WELL, i need ur help , Cause i have a problem about a program which is uploading a file from jsp-servlet.

I get this code from the other web. credits to them


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

and the TestServlet

package test;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;

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 {
PrintWriter out = response.getWriter();


boolean isMultipartContent = ServletFileUpload.isMultipartContent(request);
if (!isMultipartContent) {
out.println("You are not trying to upload<br/>");
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");
out.println("<table border=\"1\">");
while (it.hasNext()) {
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()
} 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()
} catch (FileUploadException e) {


and for my web.xml


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="file-upload" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

After I run and upload some files. I got this error

which get me crazy lol

I have common-fileupload 1.3.jar, common-fileupload-1.3-javadoc.jar,sources,tests,tests-sources

but i don't know if i had correctly used them, cause i don't know
how to use them ;3 cause i have lack of knowledge bout the built-in

I hope u help me ;3 thx in advance have a nice day