Bom dia galera,
estou precisando de uma ajudinha com o upload…
Eu preciso cadastrar no banco o nome da imagem com a sua EXTENSÃO… e o meu upload está trazendo somente o nome da imagem…
abaixo está meu Upload:
Integer idBiblioteca = null;
String documento = null;
String descricao = null;
Integer tamanho = null;
String nome = null;
DiskFileItemFactory fileupload = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(fileupload);
String path = "C:/Users/rsousa/Desktop/Cc/Intranet/WebContent/documentos";
try {
sfu.setSizeMax(2 * 1024 * 1024);
List list = sfu.parseRequest(request);
for (Iterator it = list.iterator(); it.hasNext();) {
FileItem item = (FileItem) it.next();
if (!item.isFormField()) {
documento = item.getName();
tamanho = (int) item.getSize();
documento = (new File(documento)).getName();
item.write(new File(path + "/" + documento));
item.getOutputStream().close();
// grava fisicamente
}
if (item.getFieldName().equals("idbiblioteca")) {
idBiblioteca = new Integer(item.getString());
}
if (item.getFieldName().equals("nome")) {
nome = item.getString();
}
if (item.getFieldName().equals("descricao")) {
descricao = item.getString();
}
}
DocumentoDao dd = new DocumentoDao();
try {
Integer hash = nome.hashCode();
Documento d = new Documento(null, nome, descricao,
hash.toString(), tamanho);
// grava no banco de dados
try {
dd.create(d, idBiblioteca);
request.setAttribute("mensagem",
"<script>alert('Cadastro realizado com sucesso.');</script>");
// Caso ocorra algum erro, ele mostra o passo a passo que o
// sistema
// fez até chegar ao erro. (printStackTrace).
} catch (Exception e) {
e.printStackTrace();
}
// Caso ocorra algum erro, ele mostra o passo a passo que o
// sistema
// fez até chegar ao erro. (printStackTrace).
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("idbiblioteca", idBiblioteca);
// Após a conclusão de todo o processo ele envia para a Página JSP
// abaixo.
request.getRequestDispatcher("bibliotecas.jsp").forward(request,
response);
// Caso ocorra algum erro, ele mostra o passo a passo que o sistema
// fez até chegar ao erro. (printStackTrace).
} catch (Exception e) {
e.printStackTrace();
}
Muito obrigadooo !