Dearest One,
I have created a web application in JSP & Servlet using Netbeans IDE,
i am collecting blob image into a byte[] array and displaying in a table data "<td></td>".
when i try to display the image, i am getting an exception getWriter() already called.
but when i try in a simple jsp page. it is working properly, and again i try this, this is displaying image without any table, and if i am trying to print something before or after it, it is not displaying that data.
The Code is given Below
This Code is Working Properly..
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="com.abc.DBCon"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.io.File"%>
<%@page import="java.io.OutputStream"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello JSP Upload</title>
</head>
<body>
<%
int myid=Integer.parseInt(request.getParameter("id"));
Connection con=null;
try
{
DBCon db= new DBCon();
String sql=" select photo from photo where username='"+<%session.getAttribute("user")%>+"' and id="+myid;
con=db.getCon();
con.setAutoCommit(false);
Statement st=con.createStatement();
ResultSet rs= st.executeQuery(sql);
while(rs.next())
{
byte[] imgData =rs.getBytes("photo");
response.setContentType("image/gif");
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
}
}catch(Exception ex){ex.printStackTrace();}
finally
{
try
{
con.close();
}
catch(Exception ex){ex.printStackTrace();}
}
%>
</body>
</html>
This Code is not working Properly, when i am running this code it is displaying same as previous.
but i want this image data in a fix size column.
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="com.svg.DBCon"%>
<%@page import="java.io.FileOutputStream"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.io.File"%>
<%@page import="java.io.OutputStream"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>New Page 1</title>
</head>
<body>
<table border="1" width="100%" height="836">
<tr>
<td width="33%" height="157"></td>
<td width="23%" height="157"></td>
<td width="44%" height="157"></td>
</tr>
<tr>
<td width="33%" height="216"></td>
<td width="23%" height="216" nowrap scope="col">
<%
int myid=Integer.parseInt(request.getParameter("id"));
Connection con=null;
try
{
DBCon db= new DBCon();
String sql=" select photo from photo where username='"+<%session.getAttribute("user")%>+"' and resumeid="+myid;
con=db.getCon();
con.setAutoCommit(false);
Statement st=con.createStatement();
ResultSet rs= st.executeQuery(sql);
while(rs.next())
{
byte[] imgData =rs.getBytes("photo");
response.setContentType("image/gif");
OutputStream o = response.getOutputStream();
o.write(imgData);
o.flush();
o.close();
}
}catch(Exception ex){ex.printStackTrace();}
finally
{
try
{
con.close();
}
catch(Exception ex){ex.printStackTrace();}
}
%>
</td>
<td width="44%" height="216"></td>
</tr>
<tr>
<td width="33%" height="445"></td>
<td width="23%" height="445"></td>
<td width="44%" height="445"></td>
</tr>
</table>
</body>
</html>
Thanks in Advance..