| typhoon-zsmk 
								Гость
 | 
								|  | «  : 26-07-2006 08:54 »  |  | 
 
 сервлетом пытаюсь загрузить файл клиенту из оракла, анг имена файлов отображаются в диалоге и грузятся нормально, русские в диалоге отображаются заглавной латиницей и цыфрами, совершенно левыми и каждый раз разными (даже в одной сессии), при этом если сохранить то файл нормально сохраняется, за исключением неправильности имени. Кодировки в переменной filename и contentDisposition пробовал привить по разному, разные кодировки  коннекта - не помогло.
 Код:
 
 public class filesdn extends HttpServlet {
 
 protected void doPost(HttpServletRequest req, HttpServletResponse resp)
 throws ServletException, IOException {
 
 String DBurl = "jdbc:oracle:thin:***:***";
 String dbu = "***";
 String dbp = "***";
 String dbdfn = "oracle.jdbc.OracleDriver";
 
 req.setCharacterEncoding("windows-1251");
 ServletOutputStream os = null;
 
 Properties connInfo = new Properties();
 connInfo.put("user", dbu);
 connInfo.put("password", dbp);
 connInfo.put("charSet", "Cp1251");
 Connection conn = null;
 PreparedStatement pstmt = null;
 try {
 String id = req.getParameter("id");
 conn = DriverManager.getConnection(DBurl, connInfo);;
 
 // Set the content header information
 String contentDisposition = "attachment; filename=\"";
 // Query to get the data content
 String sql = "select filename, filedata from z_ufiles where id = ?";
 pstmt = conn.prepareStatement(sql);
 pstmt.setString(1, id);
 ResultSet rs = pstmt.executeQuery();
 
 if (rs.next()) {
 Blob fileblob = rs.getBlob("filedata");
 String filename = rs.getString("filename");
 String filetype = filename.substring(filename.lastIndexOf(".") + 1, filename.length());
 String mimetype = "application/octet-stream";
 if (filetype.trim().equalsIgnoreCase("txt")) mimetype = "text/plain";
 else if (filetype.trim().equalsIgnoreCase("doc")) mimetype = "application/msword";
 else if (filetype.trim().equalsIgnoreCase("xls")) mimetype = "application/vnd.ms-excel";
 else if (filetype.trim().equalsIgnoreCase("pdf")) mimetype = "application/pdf";
 else if (filetype.trim().equalsIgnoreCase("ppt")) mimetype = "application/ppt";
 System.out.println("Найден файл: "+filename+"  type: "+mimetype);
 contentDisposition = contentDisposition + filename + "\"";
 int length = contentDisposition.length();
 StringBuffer sb = new StringBuffer(length);
 sb.append(sb);
 resp.setContentType(mimetype);
 resp.setHeader("Content-Disposition", sb.toString());
 
 InputStream in = fileblob.getBinaryStream();
 os = resp.getOutputStream();
 byte by[] = new byte[32768];
 int index = in.read(by, 0, 32768);
 while (index != -1) {
 os.write(by, 0, index);
 index = in.read(by, 0, 32768);
 }
 os.flush();
 } else {
 System.out.println("запись " + id + " не найдена");
 }
 } catch (Exception e) {
 System.out.println(e.toString());
 } finally {
 if (os != null)
 os.close();
 if (pstmt != null)
 try {
 pstmt.close();
 } catch (Exception e) {
 }
 if (conn != null)
 try {
 conn.close();
 }
 catch (Exception e) {
 }
 }
 }
 
 }
 |