Poblema com endereço

1 resposta
A

tenho um sistema de upload
ta td funcionando
mais quando eu coloco no input file um endereco com espacos e mando para o jsp que vai fazer o upload o endereco soh vai ateh
o primeiro espaço ex: c:\aa\a a\aa.jpg

<%@ page import="java.io.*"%>
<jsp:useBean id="info" class="classes.Funcoes"></jsp:useBean>

<%
	if (session.getAttribute("album") != null){
		info.conecta();
		String savePath = info.enderecoSistema+  info.mostraNomeAlbum(Integer.parseInt(session.getAttribute("album").toString())) + "\\normal\\";
		String nomeFoto = info.mostraNomeFoto();
	
		String filename = "";
	
		ServletInputStream in = request.getInputStream();
	
		byte[] line = new byte[128];
		int i = in.readLine(line, 0, 128);
		int boundaryLength = i - 2;
		String boundary = new String(line, 0, boundaryLength);
		ByteArrayOutputStream buffer = null;
		
		while (i != -1) {
			String newLine = new String(line, 0, i);
			if (newLine.startsWith("Content-Disposition: form-data; name=\"")) {
				String s = new String(line, 0, i - 2);
				int pos = s.indexOf("filename=\"");
				
				if (pos != -1) {
					String filepath = s.substring(pos + 10, s.length() - 1);
					pos = filepath.lastIndexOf("\\");
					if (pos != -1)
						filename = filepath.substring(pos + 1);
					else
						filename = filepath;
				}
	

				i = in.readLine(line, 0, 128);
				i = in.readLine(line, 0, 128);

				i = in.readLine(line, 0, 128);
	
				buffer = new ByteArrayOutputStream();
				newLine = new String(line, 0, i);
	
				while (i != -1 && !newLine.startsWith(boundary)) {
					buffer.write(line, 0, i);
					i = in.readLine(line, 0, 128);
					newLine = new String(line, 0, i);
				}
				
				//pega a extencao do arquivo
				String extencao = filename.substring(filename.lastIndexOf("."));
				filename = nomeFoto+extencao;
				//salva no banco
				info.gravaFoto(info.mostraNomeAlbum(Integer.parseInt(session.getAttribute("album").toString())) + "/normal /"+filename,Integer.parseInt(session.getAttribute("album").toString()));
				//salva arquivo
				RandomAccessFile f = new RandomAccessFile(savePath+ filename, "rw");
			
				try {
					byte[] bytes = buffer.toByteArray();
					f.write(bytes, 0, bytes.length - 2);
				} catch (Exception e) {
					f.close();
				}finally{
					f.close();
				}
			}
			i = in.readLine(line, 0, 128);
	
		} // end while
		info.desconecta();
		in.close();
		buffer.close();
	
	
		response.sendRedirect("VerAlbum.jsp?album="+session.getAttribute("album")+"&OK=true");
	}else{
		response.sendRedirect("Index.jsp");
	}
%>

1 Resposta

edmarr

qual a codificação que vc esta usando .

Criado 24 de setembro de 2009
Ultima resposta 24 de set. de 2009
Respostas 1
Participantes 2