Java code: First define a method that reads a BLOB field from an Oracle database and writes bytes to an output stream.
1 Public Static voidwriteimg (outputstream os) {2 Connection con;3 Try {4Con =connectionfactory.getconnection ();5Statement stmt =con.createstatement ();6ResultSet rs = stmt.executequery ("Select pic from blob_table where b_id=1");7 byte[] B =New byte[1024];8 if(Rs.next ()) {9Blob blob = Rs.getblob (1);TenInputStream is =Blob.getbinarystream (); One inti = 0; A while((i = Is.read (b))! =-1) { -Os.write (b, 0, i); - } the os.close (); - is.close (); - } - rs.close (); + stmt.close (); - con.close (); +}Catch(Exception e) { A e.printstacktrace (); at } -}
Then make a servlet, call the Writeimg method in the Doget method
1publicvoid doget (httpservletrequest request, httpservletresponse response) 2 throws servletexception, IOException { 3 4 dboperator.writeimg ( Response.getoutputstream ()); 5 6 }
JSP Code:<img src="Servlet/newservlet" > Reprint: Author Longdick http://longdick.iteye.com
JSP reads the image BLOB field from the Oracle database and displays it on the page < go >