Ir para conteúdo
Fórum Script Brasil

Dark Insanity

Membros
  • Total de itens

    1
  • Registro em

  • Última visita

Tudo que Dark Insanity postou

  1. Olá a todos. Sou novo aqui e já venho com um probleminha em JSP com uploads. Tento pegar o nome do diretório (que é a data) de dentro de uma consulta do banco de dados mas dá operação ilegal. Faço isso, pois uma página anterior à essa que trata a imagem é preenchida antes e depois é tratada e insere dados, os quais são retornados nesta página. Enfim, tento enviar a imagem para o diretório que seu nome lógico foi criado no banco. <%@page language="java" import="schema.Conexao"%> <%@page contentType="text/html" pageEncoding="iso-8859-1"%> <%@ page import="java.io.*"%> <%@ page import="java.util.*"%> <%@page import="java.sql.*"%> <% String diretorio = request.getParameter("ok"); try { String contentType = request.getContentType(); Connection conn = new Conexao().getConection(); String query = "SELECT date_format(EndDiretorio, '%d-%m-%Y_%H-%i-%s') as data FROM tableTopic WHERE codDiretorio = ? "; PreparedStatement pstmt = conn.prepareStatement(query); pstmt.setObject(1, diretorio); ResultSet rs = pstmt.executeQuery(); rs.next(); out.println(rs.getString("data")); // Evite criar instâncias de File utilizando "/" ou "\\" procure fazer assim: File dir = new File(application.getRealPath("/") + "eventos/"); dir = new File(dir, rs.getString("data")); dir = new File(dir, "logo"); // utilize o mkdirs para criar a estrutura de diretórios completa if (dir.mkdir()) { if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) { InputStream in = request.getInputStream(); int formDataLength = request.getContentLength(); byte dataBytes[] = new byte[formDataLength]; int byteRead = 0; int totalBytesRead = 0; while (totalBytesRead < formDataLength) { byteRead = in.read(dataBytes, totalBytesRead, formDataLength); totalBytesRead += byteRead; } String file = new String(dataBytes); String saveFile = file.substring(file.indexOf("filename=\"") + 10); saveFile = saveFile.substring(0, saveFile.indexOf("\n")); saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1, saveFile.indexOf("\"")); int lastIndex = contentType.lastIndexOf("="); String boundary = contentType.substring(lastIndex + 1, contentType.length()); int pos; pos = file.indexOf("filename=\""); pos = file.indexOf("\n", pos) + 1; pos = file.indexOf("\n", pos) + 1; pos = file.indexOf("\n", pos) + 1; int boundaryLocation = file.indexOf(boundary, pos) - 4; int startPos = ((file.substring(0, pos)).getBytes()).length; int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length; String filepath = dir + "/" + saveFile; FileOutputStream fileOut = new FileOutputStream(filepath); fileOut.write(dataBytes, startPos, (endPos - startPos)); fileOut.flush(); fileOut.close(); out.println("diretório criado e imagens enviadas para<br>" + filepath); // out.println("<img src=\"eventos/" +filePath+ "\" / >"); } else { out.println("erro ao enviar imagens para o diretório!"); } } else { out.println("erro ao criar diretório!"); } } catch (SQLException sqlex) { out.println("Não foi possível criar o evento<br>" + sqlex); } %> exceção: Não foi possível criar o evento java.sql.SQLException: Illegal operation on empty result set. Isso acontece justo no momento de pegar o nome do diretório... =/ Alguma ajudinha ? []s
×
×
  • Criar Novo...