JSP FILE-UPLOAD ERROR - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

JSP FILE-UPLOAD ERROR

LateHatredLateHatred Posts: 3Member
Hello im new! I have a problem about uploading files for jsp i got [B]common-filesupload-1.3.jar,javadoc,sources[/B]


I wanted to know what is the great solution for this. and my IDE is eclipse indigo.......I've been searching about uploading file for JSP. i got into this.. but I have a slow mind LOL :P . Hope you can help me!


Here is the code from the other web credits to them.

[B]upload.jsp[/B]
[code=java]


Files to upload:














[/code]




and for the [B]TestServlet[/B]


[code=java]
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 {
response.setContentType("text/html");
PrintWriter out = response.getWriter();

out.println("Hello
");

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

FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
try {
List fields = upload.parseRequest(request);
out.println("Number of fields: " + fields.size() + "

");
Iterator it = fields.iterator();
if (!it.hasNext()) {
out.println("No fields found");
return;
}
out.println("");
while (it.hasNext()) {
out.println("");
FileItem fileItem = it.next();
boolean isFormField = fileItem.isFormField();
if (isFormField) {
out.println("");
} else {
out.println("");
}
out.println("");
}
out.println("
regular form fieldFIELD NAME: " + fileItem.getFieldName() +
"
STRING: " + fileItem.getString()
);
out.println("
file form fieldFIELD NAME: " + fileItem.getFieldName() +
"
STRING: " + fileItem.getString() +
"
NAME: " + fileItem.getName() +
"
CONTENT TYPE: " + fileItem.getContentType() +
"
SIZE (BYTES): " + fileItem.getSize() +
"
TO STRING: " + fileItem.toString()
);
out.println("
");
} catch (FileUploadException e) {
e.printStackTrace();
}
}
}[/code]

For the [B]web.xml[/B]



[code=java]
<?xml version="1.0" encoding="UTF-8"?>


TestServlet
test.TestServlet


TestServlet
/test

][/code]

When i run this program, i got this error....


[img=http://img59.imageshack.us/img59/9362/errvoc.jpg]


PLEASE DO HELP ME THX IN ADVANCE, ask me somethin
Sign In or Register to comment.