pessoal estou tentando fazer um upload usando a commons.fileupload da jakarta peguei um código aqui do guj mesmo mas esta me retornando um erro:
upload.jsp
<%@ page import="org.apache.commons.fileupload.*, java.util.List, java.io.File, java.util.Iterator" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
</head>
<body>
<%
// first check if the upload request coming in is a multipart request
boolean isMultipart = FileUpload.isMultipartContent(request);
DiskFileUpload upload = new DiskFileUpload();
upload.setSizeMax(1024*1024*3); // 3 Mb
// parse this request by the handler
// this gives us a list of items from the request
List items = upload.parseRequest(request);
Iterator itr = items.iterator();
while(itr.hasNext()) {
FileItem item = (FileItem) itr.next();
// check if the current item not is a form field or an uploaded file
if(!item.isFormField()) {
// the item must be an uploaded file save it to disk. Note that there
// seems to be a bug in item.getName() as it returns the full path on
// the client's machine for the uploaded file name, instead of the file
// name only. To overcome that, I have used a workaround using
// fullFile.getName().
File fullFile = new File(item.getName());
String nome = fullFile.getName();//pega o nome do arquivo
String extensao=nome.substring(nome.length()-3,nome.length());//pega a estenção do arquivo
out.println(nome+"<br>");
out.println(extensao+"<br>");
if (extensao.equalsIgnoreCase("JPG")) {//só envia se for JPG
File savedFile = new File(getServletContext().getRealPath("/ola/"),fullFile.getName());
item.write(savedFile);
}
else {
out.println("Não enviando. Use apenas JPG");
}
}
}
%>
</body>
</html>
mas esta me dando o seguinte erro:
org.apache.jasper.JasperException: An exception occurred processing JSP page /administrativo/cad_banners/upload.jsp at line 22
19: upload.setSizeMax(1024*1024*3); // 3 Mb
20: // parse this request by the handler
21: // this gives us a list of items from the request
22: List items = upload.parseRequest(request);
23:
24: Iterator itr = items.iterator();
25:
Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
se alguem puder me ajudar!
