Hello. I want the user to be able to upload a file, and then I want to read the file and do some stuff with it.
I searched around and found out that to do this I needed to use a third party library. I found the Commons FileUpload, but I cant seem to make it work. I tried to use the mailing list, but I have gotten no respons.
In the jsp
***uploadPhoto.jsp ***
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="org.apache.commons.fileupload.*"%>
<%@ page import="org.apache.commons.fileupload.servlet.*"%>
<%@ page import="org.apache.commons.fileupload.portlet.*"%>
<%@ page import="org.apache.commons.collections.*"%>
<%@ page import="java.util.*"%>
<%
boolean isMultipart = ServletFileUpload.isMultipartContent(request);
out.println("" + isMultipart);
// Parse the request
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream stream = item.openStream();
if (item.isFormField()) {
out.println("Form field " + name + " with value "
+ StreamUtil.asString(stream) + " detected.");
} else {
out.println("File field " + name + " with file name "
+ item.getName() + " detected.");
// Process the input stream
}
}
%>
The first line returns true. So I know I have a file. But the next one I get an error saying "Cannot find type FileItemIterator.
I tried to include as much libraries as I thought needed, but still the same error.
I have put the commons fileupload jar in my WEB-INF/lib directory, and also in my application.jar file.
Can someone help me please?
Message was edited by:
asgshe