html - 显示数据库中的图像

标签 html mysql jsp

我在 JSP 中创建了一个程序来获取图像并将其显示在网页上。程序运行正常,图像显示,但其他内容不显示。下面是代码

<% 
        byte[] imgData = null ;
        Class.forName("com.mysql.jdbc.Driver");
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/buysell","root","root");
         Statement stmt = con.createStatement();       
 ResultSet resultset =stmt.executeQuery("select * from imagemain where id=1;") ; 
  while(resultset.next())  
  {
      Blob bl = resultset.getBlob(2);
byte[] pict = bl.getBytes(1,(int)bl.length());
response.setContentType("image/jpg");
OutputStream o = response.getOutputStream();
%>
<img src="<%o.write(pict);%>" width="10" height="10">
<h1>Vishal</h1>
<%
out.print("1");
o.flush();
o.close();
  } 
        %>

程序未显示<h1>Vishal</h1> 。请协助解决此问题

最佳答案

您需要了解标准 http 访问的工作原理

现在尝试

response.setContentType("text/html");
OutputStream o = response.getOutputStream();
%><img src="data:image/jpg;base64,    <%o.write(Base64.encode(pict));%>" width="10" height="10">
   <h1>Vishal</h1>

更多信息请点击:How to display an image which is in bytes to JSP page using HTML tags?

或者

<img src="otherjspreturningimage.jsp" />

关于html - 显示数据库中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18314656/

相关文章:

java - 在 Struts2 中使用拦截器传输用户数据

spring - 此 Spring Boot 项目的 Gradle + jsp

javascript - 单选按钮仅在 DataTable 的第一个表中附加一个事件

javascript - 使用 json 发送电子邮件

python - pyodbc 是否支持任何形式的命名参数?

php - 用 PHP 文件中的内容替换 div 内容

mysql - 我如何使用 django migrations.RunSQL 和 MySQL 删除索引(如果存在)

mysql - 实时网站速度减慢太多

html - 应用显示 :block class directly 时 Bootstrap 模式不关闭

html - 如何使用CSS将不同的悬停颜色效果应用于不同的li