Olá galera do guj, estou tentando desenvolver um sistema web para exibir produtos no site. tenho um banco de dados no mysql que possui imagens cadastradas e agora estou querendo saber como fazer para exibir as imagens na página com jsp. abaixo tenho um código para fazer a exibição mais está exibindo o codigo da imagem. é necessário fazer algum tratamento para poder fazer isso? e como fazer?
1. <%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*, java.io.*" errorPage="" %>
2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3. <html xmlns="http://www.w3.org/1999/xhtml">
4. <head>
5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6. <title>Untitled Document</title>
7. <style type="text/css">
8. <!--
9. .style1 {
10. color: #FF0000;
11. font-weight: bold;
12. font-size: 36px;
13. }
14. -->
15. </style>
16. </head>
17.
18. <body>
19. <div align="center"><span class="style1">Lista de Produtos</span></div>
20. <p>
21. <%
22. try{
23.
24. Class.forName("com.mysql.jdbc.Driver");
25. Connection con = DriverManager.getConnection("jdbc:mysql://localhost/master","root","senha");
26. String sql = "select descricao_do_produto, foto from produtos";
27. PreparedStatement smt = con.prepareStatement(sql);
28. ResultSet rs = smt.executeQuery();
29. while(rs.next()){
30.
31. %>
32.
33. </p>
34. <form id="form1" name="form1" method="post" action="listarProdutos.jsp">
35. <table width="200" border="1">
36. <tr>
37. <td>produto</td>
38. <td>Imagem</td>
39. </tr>
40. <tr>
41. <td><%=rs.getString("descricao_do_produto")%></td>
42. <td><%=rs.getBytes("foto")%></td>
43. </tr>
44. </table>
45. <%
46. }
47.
48.
49. }catch(ClassNotFoundException erroClasse){
50. out.println("Erro na Classe de Conexão!" + erroClasse);
51. }catch(SQLException erroSQL){
52. out.println("Erro ao listar dados do banco! " + erroSQL);
53. }
54. %>
55. </form>
56. <p> </p>
57. </body>
58. </html>