boa tarde estou tentando criar um upload de arquivos num projeto que estou fazendo da faculdade
to usando o hibernate 2.0 , primefaces 2.2.1
coloquei tbm o jar (commons-fileupload-1.2.2 e commons-io-2.0.1)
aew a minha tela (.xhtml) o icone ta assim:
o meu backbean ta assim
public void criaArquivo(byte[] bytes, String arquivo) {
FileOutputStream fos;
try {
fos = new FileOutputStream(arquivo);
fos.write(bytes);
fos.close();
} catch (FileNotFoundException ex) {
System.out.println("erro " + ex.getMessage());
} catch (IOException ex) {
System.out.println("erro " + ex.getMessage());
}
}
public void enviarImagem(FileUploadEvent event) {
byte[] img = event.getFile().getContents();
imagemTemporaria = event.getFile().getFileName();
FacesContext facesContext = FacesContext.getCurrentInstance();
ServletContext scontext = (ServletContext) facesContext.getExternalContext().getContext();
String arquivo = scontext.getRealPath("/upload/" + imagemTemporaria);
criaArquivo(img, arquivo);
}
e o meu web.xml ta assim(nesse parte é que ta a grande bronca pq nao to sabendo colocar a parte de baixo com a parte de cima que era
a que ja estava no projeto)
<?xml version="1.0" encoding="UTF-8"?>
javax.faces.PROJECT_STAGE
Development
Controle de acesso
FiltroRunCase
br.com.runcase.web.FiltroRunCase
FiltroRunCase
*.xhtml
REQUEST
FORWARD
15
faces/paginaPrincipal.xhtml
-------------------------------------------------------------------------------------------
essa parte aqui pelo que pesquisei tem que ta no web.xml para poder funcionar o upload
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
será que vocês podem me ajudar?