2014-05-14 6 views
0

내 문제는 내 jsp에서 mysql 데이터베이스에 중간 크기의 blob을 표시 할 수 있었다면 내 css로 이미지를 배치 할 수 없다는 것입니다.asp div에 이미지 표시

내가 원하는 것은 고정 너비와 높이를 가진 div 안에 위치시키는 것입니다.

<%@page import="java.io.OutputStream"%> 
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>JSP Page</title> 
    </head> 
    <body> 
     <% 

      Statement stmnt = null; 
      ResultSet rs = null; 
      OutputStream o = null; 
      String driver = "com.mysql.jdbc.Driver"; 
      String url = "jdbc:mysql://localhost/uShare"; 
      String username = "root"; 
      String password = ""; 
      PreparedStatement ps; 
      Blob image = null; 
      byte[] imgData = null; 
      try { 
       Class.forName(driver).newInstance(); 
       Connection con = DriverManager.getConnection(url, username, password); 
       stmnt = con.createStatement(); 
       rs = stmnt.executeQuery("select foto from utilizadores where idUtilizador = 13"); 
       if (rs.next()) { 
        image = rs.getBlob("foto"); 
        imgData = image.getBytes(1, (int) image.length()); 
        out.println("encontrou imagem"); 
       } 
       //mostra 
       response.setContentType("image/gif"); 
       o = response.getOutputStream(); 
       o.write(imgData); 

     %> 
     <div style="float: right; width: 20%; height: 20%;"> 
      <% 
       o.flush(); 


      %> 

     </div> 

     <% 
       o.close(); 
       stmnt.close(); 
       con.close(); 
      } catch (SQLException ex) { 
       ex.printStackTrace(); 
      } 
     %> 
    </body> 
</html> 

고맙습니다. 100 %로

+1

java/jsp/mysql과는 어떤 관계가 있습니까? 이는 순수한 서버 측 기술입니다. html 및 css - ** CLIENT ** 기술에 대한 도움이 필요합니다. –

+0

당신 말이 맞아요,하지만 거기에 ASP 페이지에 이미지를 업로드하는 다른 방법이있을 것이라고 생각하고 있습니다. mySql 태그를 제거합니다 –

답변

0

죄송 사업부의 고정 된 길이의 내부에 들어가 얻을 수 있도록 있지만 사이트 나 모두 8 hours.T 행크스 이내에 응답하지 않습니다. 나는 일시적인 해결책을 발견했다. 그리고 이것은 학문적 목적만을위한 것이기 때문에 그것은 괜찮다.

솔루션입니다. 언제 내가 태그에 이미지를 표시하려면, 나는 항상 URL을 태그를 부여해야합니다.
두 가지 가능성이 있습니다

  • 당신이 서블릿을 통해 이미지를 전달 캠;
  • 또는 내가 한 것처럼, JSP 페이지에서 이미지를 표시 한 다음 첫 번째 JSP URL과 함께 다른 JSP로 가져옵니다.

JSP로 디스플레이의 이미지 :

<%@page import="java.io.OutputStream"%> 
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>JSP Page</title> 
     <link href="css/master.css" rel="stylesheet" type="text/css"> 
    </head> 
    <body> 
     <% 

      Statement stmnt = null; 
      ResultSet rs = null; 
      OutputStream o = null; 
      String driver = "com.mysql.jdbc.Driver"; 
      String url = "jdbc:mysql://localhost/uShare"; 
      String username = "root"; 
      String password = ""; 
      PreparedStatement ps; 
      Blob image = null; 
      byte[] imgData = null; 
      try { 
       Class.forName(driver).newInstance(); 
       Connection con = DriverManager.getConnection(url, username, password); 
       stmnt = con.createStatement(); 
       rs = stmnt.executeQuery("select foto from utilizadores where idUtilizador = 13"); 
       if (rs.next()) { 
        image = rs.getBlob("foto"); 
        imgData = image.getBytes(1, (int) image.length()); 
        out.println("encontrou imagem"); 
       } 
       //mostra 

       response.setContentType("image/jpeg"); 
       o = response.getOutputStream(); 
       o.write(imgData); 
       o.flush(); 

       response.flushBuffer(); 


       stmnt.close(); 
       con.close(); 
      } catch (SQLException ex) { 
       ex.printStackTrace(); 
      } 
     %> 
    </body> 
</html> 

그리고 최종 사용자 JSP 물론

<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
     <title>JSP Page</title> 
    </head> 
    <body> 
     <img src="testeImagem.jsp" alt="foto" style="width: 200px; height: 200px"> 

    </body> 
</html> 

이것은 단지 예제이다. 모두에게 감사하고, 나쁜 영어로 유감스럽게 생각합니다.

-1

설정 이미지 너비는 후반 답변

+0

그리고 어떻게해야합니까? 출력 스트림을 div로 플러시하고 div의 너비와 높이를 고정했습니다. 플러시 출력이 div에 맞아야한다는 뜻입니까? –

+0

친애하는 Xaver 당신은 사용자가 묻는 질문과 같은 문제에 직면하고 있습니까? –