| | |
View Image in jsp
Please support our JSP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2007
Posts: 6
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 10:48 pm. Reason: Keep It Organized - please use [code] tags
Abhilash Narayan
Java Programmer
Java Programmer
![]() |
Similar Threads
- 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)
Other Threads in the JSP Forum
- Previous Thread: passing and retrieving arguments
- Next Thread: sending email
| Thread Tools | Search this Thread |
apache backbutton combobox connection database development directorystructure dynamicpagetitles eclipse frames glassfish imagetodatabse imageupload internet java javaee javascript jsf jsp jsppagetitles levels mvc2 mvcmodel2 network parameters passing ping printinserverinsteadofclient redirect request.getparameter response servlet servletdopost()readxml sessions software ssl state_saving_method stocks sun tomcat tutorial video web






