how to display image in jsp from java class.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   G_K
Posted On:   Tuesday, March 21, 2006 07:56 AM

how to display image in jsp from java class.Following code by which i can display in JFrame.But cannot able to display on jsp . import javax.swing.*; /* CREATE TABLE report ( patientid VARCHAR (10) NOT NULL, xray BLOB , ) */ import java.awt.*; import java.io.*; import java.sql.*; import java.sql.*; import java.util.*; public class InsertDisplayJPG extends JFrame { public static void main(String p[]) throws Exception { InsertDisplayJPG i= new InsertDisplayJPG(); } public ArrayList I   More>>


how to display image in jsp from java class.Following code by which i can display in JFrame.But cannot able to display on jsp .



import javax.swing.*;


/*

CREATE TABLE report (
patientid VARCHAR (10) NOT NULL,
xray BLOB ,

)

*/
import java.awt.*;

import java.io.*;


import java.sql.*;


import java.sql.*;


import java.util.*;



public class InsertDisplayJPG extends JFrame
{


public static void main(String p[]) throws Exception
{


InsertDisplayJPG i= new InsertDisplayJPG();
}


public ArrayList InsertDisplay()throws Exception
{


ArrayList al=new ArrayList();


Class.forName("oracle.jdbc.driver.OracleDriver");


Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@192.168.100.149:1521:ghdb","hitechtest","TEST");


System.out.println("Conn");


//PreparedStatement pst=conn.prepareStatement("insert into report values(?,?)");


PreparedStatement pst=conn.prepareStatement("insert into report values(?,?)");


File f=new File("c:/images/three.gif");


System.out.println(f);


//File f=new File("..\images\two.gif");


//File f1=new File("..\barium_enema.JPEG");


String str=f.getAbsolutePath();


System.out.println("--->"+str);



FileInputStream fis=new FileInputStream(f);


pst.setString(1,"ip");


System.out.println("1");


pst.setBinaryStream(2,fis,(int)(f.length()));


System.out.println("2");


int i=pst.executeUpdate();


System.out.println("Updated**:"+i);



Container ct=getContentPane();


pst=conn.prepareStatement("select xray from report");


//pst.setString(1,"shirt");
ResultSet rs=pst.executeQuery();


rs.next();


ByteArrayOutputStream bos=new ByteArrayOutputStream();


InputStream i1=rs.getBinaryStream(1);


FileOutputStream fos=new FileOutputStream("c:/IMAGES/sss.gif");


int val=i1.read();


while(val!=-1)


{


bos.write(val);


fos.write(val);


val=i1.read();


}
rs.close();


fos.close();



JButton jb=new JButton("");


ImageIcon ic=new ImageIcon(bos.toByteArray());


Icon ii=ic;


ct.add(jb);


jb.setIcon(ii);


setSize(300,500);


byte[]st=bos.toByteArray();


System.out.println(st);


al.add(st);


setVisible(true);


return al;

}}



I am using following code to display the image.


if(a.size()>0){


%>


//a.get(0);

<%} %>


please help me.

   <<Less

Re: how to display image in jsp from java class.

Posted By:   WarnerJan_Veldhuis  
Posted On:   Tuesday, March 21, 2006 11:42 AM

Getting an image is a separate request. A browser reads the html, then goes back to the server for each image. Create a servlet that specifically handles the requests for dynamic images:
About | Sitemap | Contact