Внимание! Привожу последний вариант метода doPost: Появились setContentLength() и close(), но получение рисунка все-равно не работает. А вот запись байтов в файл (выделено жирным) работает!!! Получается нормальный jpg рисунок.
| Код | public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
performTask(request, response); //response.setContentType("text/html;charset=Windows-1251"); response.setContentType("image/jpeg"); //response.setContentType("application/download"); //прослеживанию сеанс HttpSession hs = request.getSession(true); String s = (String) hs.getValue("correct"); if ((s != null) && (s.equals(ValueCorrectSeanse))) { try { Class.forName(MySQLDriver).newInstance(); Properties connInfo = new Properties(); connInfo.put("user",MySQLUser); connInfo.put("password",MySQLPassword); connInfo.put("useUnicode","true"); connInfo.put("characterEncoding",MySQLcharacterEncoding);
//Conn = DriverManager.getConnection(MySQLUrl,MySQLUser,MySQLPassword); Conn = DriverManager.getConnection(MySQLUrl,connInfo); Stmt = Conn.createStatement(); //Пытаюсь заюзать базу Stmt.executeUpdate("USE news"); RS = Stmt.executeQuery("SELECT image FROM News_images where rowid=1"); while (RS.next()) { com.mysql.jdbc.Blob bl = null; bl = (com.mysql.jdbc.Blob) RS.getBlob("image"); [b]OutputStream f1 = new FileOutputStream("c:/temp/file111.jpg"); f1.write(bl.getBytes(1,(int) bl.length())); f1.close();[/b] response.setContentLength((int) bl.length()); //Создать объект класса ObjectOutputStream. ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream()); //запись в поток out.write(bl.getBytes(1,(int) bl.length())); //Очистить поток, чтобы быть уверенным в том, что всё содержимое послано клиенту. out.flush(); out.close(); } } catch (Exception E) { //pw.println(MesageError); //pw.println(E); } //конец ифа ниже } else { //pw.println("<H2>"+AcessDenied+"<H2>"); } } |
В чем же проблема |