[RESOLVIDO] Obter foto do SQLServer no resultSet via scriptlet

3 respostas
jMarcel

Pessoal,

tenho uma tabela com nome, idade e foto, por ex.

Quero mostrar, via jsp, esses dados.

Fiz o seguinte:

<img alt="" title="<%=rsSuper.getBlob("foto").getBytes(1, (int) blob.length())%>" />
<h3><%=rsSuper.getString("Nome")%></h3>
//...

Visto que Blob é abstrato, não posso instanciá-lo.

Alguém sabe como fazer ?

3 Respostas

R

Não tinha como delegar pra um método ler essa foto e apenas jogar os bytes no response?

jMarcel

Pesquisei e consegui printar a imagem no browser, mas agor não estou conseguindo emoldura-la pelo .css. Você sabe como fazer ? Veja abaixo o código.

jMarcel
Alguém saberia como posso emoldurar a imagem no .css, de acordo com a imagem printada pelo código abaixo: jsp:
<%
Connection con = FactoryConnection_SQL_SERVER.getConnection("Organograma");
Statement stSuper = con.createStatement();
Statement stSetor = con.createStatement();

Blob image = null;
byte[] imgData = null;

ResultSet rsSuper = stSuper.executeQuery("Select * From funChart where setor = 'mySetor'");

if (rsSuper.next()) {
image = rsSuper.getBlob(12);
imgData = image.getBytes(1, (int) image.length());
response.setContentType("image/gif");
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();

--[...]

<table style="margin: 0px; margin-top: 15px;">
<tr>
<td id="foto">
    <img title="<%=rsSuper.getString("Nome").trim()%>" src="<%= o.wite(imageData); %>" />
</td>
</td>

<td id="dados">
<h3><%=rsSuper.getString("Nome")%></h3>
<p><%=rsSuper.getString("Cargo")%></p>
<p>Matrícula:<br/><%=rsSuper.getString("Chave")%></p>
<p>Telefone:<br/><%=rsSuper.getString("Fone")%></p>
<p>E-Mail:<br/><%=rsSuper.getString("Email")%></p>
</td>
</table>

.css:

#foto
{
    padding: 0px;
    vertical-align: middle;
    text-align: center;
    width: 170px;
    height: 220px;
}

A imagem é exibida, mas está ocupando a página toda.

Criado 21 de junho de 2012
Ultima resposta 22 de jun. de 2012
Respostas 3
Participantes 2