widiyantosg
asked on
Displaying blob on jsp
Hi
I am trying to display my image that is saved inside mysql in blob format in jsp. but I can not display the picture.
in viewInventoryimage.jsp:
<%@ page import="db.*,java.sql.*" %>
<%
String id = request.getParameter("id") ;
out.println("id:"+id);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#F0F0F0">
<form action="form1" method="post" enctype="multipart/form-da ta">
<table width="45" height="44" border="1">
<tr>
<td width="36"><img src="inventory_action1.jsp ?action=vi ewImage&id =<%=id%>"> </td>
</tr>
</table>
</form>
</body>
</html>
in inventory_action.jsp:
else if(action.equals("viewImag e"))
{
sql = "SELECT image_path FROM inventory WHERE id = '"+id+"'";
rs = stmt.executeQuery(sql);
response.setContentType("i mage/jpeg" ) ;
if(rs.next())
{
byte[] bytearray = new byte[4096];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStream(4);
response.reset();
response.setContentType("i mage/jpeg" );
response.addHeader("Conten t-Disposit ion","file name=getim age.jpeg") ;
while((size=sImage.read(by tearray))! = -1 )
{
response.getOutputStream() .write(byt earray,0,s ize);
}
response.flushBuffer();
sImage.close();
}
out.flush();
}
stmt.close();
can anybody tell me wat is the error? Thank you
I am trying to display my image that is saved inside mysql in blob format in jsp. but I can not display the picture.
in viewInventoryimage.jsp:
<%@ page import="db.*,java.sql.*" %>
<%
String id = request.getParameter("id")
out.println("id:"+id);
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#F0F0F0">
<form action="form1" method="post" enctype="multipart/form-da
<table width="45" height="44" border="1">
<tr>
<td width="36"><img src="inventory_action1.jsp
</tr>
</table>
</form>
</body>
</html>
in inventory_action.jsp:
else if(action.equals("viewImag
{
sql = "SELECT image_path FROM inventory WHERE id = '"+id+"'";
rs = stmt.executeQuery(sql);
response.setContentType("i
if(rs.next())
{
byte[] bytearray = new byte[4096];
int size=0;
InputStream sImage;
sImage = rs.getBinaryStream(4);
response.reset();
response.setContentType("i
response.addHeader("Conten
while((size=sImage.read(by
{
response.getOutputStream()
}
response.flushBuffer();
sImage.close();
}
out.flush();
}
stmt.close();
can anybody tell me wat is the error? Thank you
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER