How to give
servlet response form the dotag() method in which i am retrieving image from database and i have to display it on
jsp page where i am calling this tag.
I am not geting the servlet response there .
Can any one help how to write that code.
//Code goes like this..
package com.bean;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ResourceBundle;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;
public class DisplayTag extends SimpleTagSupport
{
public void doTag() throws JspException, IOException {
JspWriter out = getJspContext().getOut();
try {
ResourceBundle rb = ResourceBundle.getBundle("com.bean.messages");
String username = rb.getString("username");
String password = rb.getString("password");
String url = rb.getString("url");
String driver = rb.getString("driver");
Class.forName(driver).newInstance();
Connection con = (Connection) DriverManager.getConnection(url, username,password);
Statement st = con.createStatement();
ResultSet rs=null;
rs=st.executeQuery("select img from image ORDER BY RAND() LIMIT 1");
String imglen="";
while(rs.next())
{
imglen = rs.getString(1);
System.out.println(imglen.length());
int len=imglen.length();
byte [] b=new byte[len];
InputStream in=rs.getBinaryStream(1);
int i= in.read(b,0, len);
System.out.println("bytes"+b.length);
System.out.println("index"+i);
out.write("Hai this is sagar");
// here hw we can write......
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}