Reputation: 43
I have created a program in JSP to fetch the image and display it on web page. Program is working correctly image is displayed but other contents are not displaying. Below is the code
<%
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();
}
%>
the program is not displaying the <h1>Vishal</h1>
. Please assist on this
Upvotes: 0
Views: 729
Reputation: 177692
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" />
Upvotes: 1