0

我在 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>. 请协助

4

1 回答 1

1

You need to read up on how standard http access works

For now try

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>

More info here: How to display an image which is in bytes to JSP page using HTML tags?

OR

<img src="otherjspreturningimage.jsp" />
于 2013-08-19T13:36:03.233 回答