View Image in jsp
Please support our JSP advertiser: Programming Forums
![]() |
•
•
Posts: 5
Reputation:
Solved Threads: 0
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..
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.
Thanks in Advance..
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..
html Syntax (Toggle Plain Text)
<%@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.
html Syntax (Toggle Plain Text)
<%@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..
Last edited by peter_budo : Mar 17th, 2008 at 9:48 pm. Reason: Keep It Organized - please use [code] tags
Abhilash Narayan
Java Programmer
Java Programmer
![]() |
Similar Threads
Other Threads in the JSP Forum
- Need Javascript Help for Display Images (JavaScript / DHTML / AJAX)
- Go to a certain page when button is pressed and do it securely (ASP.NET)
- Unable to read a site with JSP coding (JSP)
- Unmetered Web space for Reseller Web Hosting from WebHostingWith.us (Web Hosting Deals)
- Forwarding Hotmail with attachments (Windows NT / 2000 / XP / 2003)
Other Threads in the JSP Forum
- Previous Thread: passing and retrieving arguments
- Next Thread: sending email
•
•
•
•
Views: 2601 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)






Linear Mode