• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrive image from MySQL database in fix format on JSP page

 
rutvi gen
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all.

My problem is like this- I am storing image in MySQL database and now i have to retrieve those image on my JSP page. I am able to retrieve those image on JSP page but the problem is that i cant fix those size. Image is being retrieved in their original format only. Can anyone tell me how can i put them in fixed format???

Thanks in advance.
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rutvi,

Can you please post some of your code, and the format of the images in the database and the "FIXED" format to be displayed in jsp ? That will help us a lot ...as to how it can be solved?
 
rutvi gen
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection( "jdbc:mysql://192.168.4.29:3306/pts?","root","root");
PreparedStatement pst = conn.prepareStatement("SELECT image FROM image WHERE devID = ?");
pst.setString(1, "dv11");
ResultSet rs = pst.executeQuery();
if(rs.next()) {
byte[] bytearray = new byte[1048576];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStream(1);
response.reset();
response.setContentType("image/jpeg");
response.addHeader("Content-Disposition","filename=logo.jpg");
while((size=sImage.read(bytearray))!= -1 )
{
%>
<table border="1">
<tr>
<td width="100" height="100">
<%
response.getOutputStream().write(bytearray,0,size);
%>
</td>
</tr>
</table>
<%
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You appear to be mixing HTML tags with binary image data. Think about it! When a browser sees an IMG tag it starts a separate request to get the image data only.

Serving binary data should be done from a servlet, JSP is for character data. The response outputStream is trying to send character data.

MANY MANY posts on this forum have covered this problem, do some searching.

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!