Olá pessoal,
Preciso de sua ajuda para corrigir.
Eu criei seguinte:
UploadBean.java
package meupacote;
import java.io.File;
import java.util.*;
import org.apache. commons.fileupload.*;
import org.apache. commons.fileupload.disk.DiskFileItemFactory;
import org.apache. commons.fileupload.servlet.ServletFileUpload;
import javax.servlet.ServletContext;
import javax.servlet.http.*;
public class UploadBean {
private DiskFileItemFactory fileUpload = new DiskFileItemFactory();
private ServletFileUpload sfu = new ServletFileUpload(fileUpload);
private String diretorio;
private String filename;
public void setDiretorio (String diretorio){
this.diretorio = diretorio;
}
public String getDiretorio(){
return diretorio;
}
public String getFilename(){
return filename;
}
public boolean doFilePost (HttpServletRequest request, ServletContext context) {
if (request.getContentType() == null)
return false;
if (!request.getContentType().startsWith("multipart/form-data"))
return false;
String path = context.getRealPath(getDiretorio());
try {
List list = sfu.parseRequest(request);
Iterator iterator = list.iterator();
while(iterator.hasNext()){
FileItem item = (FileItem)iterator.next();
if (!item.isFormField()){
filename = item.getName();
if((filename != null) && (!filename.equals(""))){
filename = (new File(filename)).getName();
item.write(new File (path + "/"+ filename));
}
}
}
}catch (FileUploadException e) {
e.printStackTrace();
}catch (Exception e) {
e.printStackTrace();
}
return true;
}
}
fazendoUploadComJsp.jsp
<%@ page language="java"
contentType="text/html"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Fazendo Upload de arquivos</title>
</head>
<body>
<jsp:useBean id="up1" scope="page" class="meupacote.UploadBean" />
<jsp:setProperty name="up1" property="diretorio" value="arquivos"/>
<%
if(up1.doFilePost(request,application)){
out.println(up1.getFilename());
%>
<form method="post" action="fazendoUploadComJsp.jsp" enctype="multipart/form-data"><br />
Arquivo: <input type="file" name="file" /> <br />
<input type ="submit" name="submit" value="Enviar" />
</form>
</body>
</html>
Apareceu os erros embaixo:
init:
deps-module-jar:
deps-ear-jar:
deps-jar:
library-inclusion-in-archive:
library-inclusion-in-manifest:
compile:
compile-jsps:
Compiling 1 source file to C:\Users\XXXXXXXXXX\Documents\NetBeansProjects\Upload\build\generated\classes
C:\Users\XXXXXXXXXX\Documents\NetBeansProjects\Upload\build\generated\src\org\apache\jsp\fazendoUploadComJsp_jsp.java:89: ‘catch’ without ‘try’
} catch (Throwable t) {
C:\Users\XXXXXXXXXX\Documents\NetBeansProjects\Upload\build\generated\src\org\apache\jsp\fazendoUploadComJsp_jsp.java:89: ‘)’ expected
} catch (Throwable t) {
C:\Users\XXXXXXXXXX\Documents\NetBeansProjects\Upload\build\generated\src\org\apache\jsp\fazendoUploadComJsp_jsp.java:89: not a statement
} catch (Throwable t) {
C:\Users\XXXXXXXXXX\Documents\NetBeansProjects\Upload\build\generated\src\org\apache\jsp\fazendoUploadComJsp_jsp.java:89: ‘;’ expected
} catch (Throwable t) {
C:\Users\XXXXXXXXXX\Documents\NetBeansProjects\Upload\build\generated\src\org\apache\jsp\fazendoUploadComJsp_jsp.java:96: ‘finally’ without ‘try’
} finally {
C:\Users\XXXXXXXXXX\Documents\NetBeansProjects\Upload\build\generated\src\org\apache\jsp\fazendoUploadComJsp_jsp.java:42: ‘try’ without ‘catch’ or ‘finally’
try {
C:\Users\XXXXXXXXXX\Documents\NetBeansProjects\Upload\build\generated\src\org\apache\jsp\fazendoUploadComJsp_jsp.java:100: reached end of file while parsing
}
7 errors
C:\Users\XXXXXXXXXX\Documents\NetBeansProjects\Upload\nbproject\build-impl.xml:483: The following error occurred while executing this line:
C:\Users\XXXXXXXXXX\Documents\NetBeansProjects\Upload\nbproject\build-impl.xml:231: Compile failed; see the compiler error output for details.
FALHA NA CONSTRUÇÃO (tempo total: 0 segundos)
Obs.: uso Netbeans IDE 6.8