我在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>
。請幫助這個
調試?查詢是否工作 - >在數據庫客戶端(MySQL管理員,SQLYOG或phpmyadmin)中運行它以查看。 while循環運行?結果集可能是NULL? –
感謝Raymond爲您的迴應...圖像顯示正確,但其他HTML內容像「
Vishal
」無法正確顯示。 – vishal您正在返回一張圖片。要顯示文本和圖像,您需要兩次http訪問或使用B64編碼創建數據URI。在這兩種情況下,你需要開始與文本/ html – mplungjan