Re: How to get and store uploaded file on server in JSP
snehapshinde@gmail.com wrote:
On Aug 28, 5:55 am, Arne Vajh?j <a...@vajhoej.dk> wrote:
Code snippet that processes multiple files:
<%@page import="org.apache.commons.fileupload.*,java.util.*,java.io.*"%>
<%
DiskFileUpload upload = new DiskFileUpload();
List files = upload.parseRequest(request);
for(int i = 0; i < files.size(); i++) {
FileItem file = (FileItem)files.get(i);
if(file.getSize() > 0) {
String filename = "C:\\" + file.getFieldName() + ".upl";
file.write(new File(filename));
}}
%>
I tried with this piece of code, but it is throwing following
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 2 in the jsp file: /upload.jsp
Generated servlet error:
DiskFileUpload cannot be resolved or is not a type
I don't understand why is it not able to recognize DiskFileUpload and
FileItem, even though org.apache.commons.fileupload.* has been
imported! Could you please tell me what would be the probable
problem?
import="org.apache.commons.fileupload.*
just imports names - it means that DiskFileUpload can be used as
abbreviation for org.apache.commons.fileupload.DiskFileUpload - it does
not import any code.
The error is with almost certainty that you have not put the
Jakarta FileUpload jar files in classpath. They should be in
WEB-INF/lib !
Arne