dcsimg
Image Source in a html, pointing to a Servlet.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Munira_F
Posted On:   Thursday, April 12, 2001 04:34 AM

hi I am developing a web application using JSP-Servlet technology in WebSphere. The backend is Oracle 8i. Here images are stored as BLOB data type in Database. Now I have a html page which has 150 images. The source of these images is mentioned as below. "IMG SRC='/servlet/ImageServlet?ImageName=abc'" ImageServlet selects this blob data from backend and writes it in ServletOutputStream. The code is as below. public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException{ Connection con = null; Statement stmt = null; OracleResultSet ors = null; Blob blobdata = null;    More>>

hi

I am developing a web application using JSP-Servlet technology in WebSphere. The backend is

Oracle 8i. Here images are stored as BLOB data type in Database. Now I have a html page which has

150 images. The source of these images is mentioned as below.
"IMG SRC='/servlet/ImageServlet?ImageName=abc'"


ImageServlet selects this blob data from backend and writes it in ServletOutputStream. The code

is as below.

public void doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException,

IOException{

Connection con = null;
Statement stmt = null;
OracleResultSet ors = null;
Blob blobdata = null;

try {

// get ImageNmae
String lstrIN = req.getParameter("ImageName");

// getConnection
con = dbConnection.getConnection();
stmt = con.createStatement();

StringBuffer lstrSQL = new StringBuffer();

lstrSQL.append("SELECT IMAGE FROM IMAGETABLE WHERE IMAGENAME='"+lstrIN+"'");

ors = (OracleResultSet) stmt.executeQuery(lstrSQL.toString());

if (ors != null) {
if (ors.next()) {
blobdata = ors.getBlob("IMAGE");
lstrImageTypeFromDB = ors.getString("IMAGETYPE");
}
}//if

// Throw the image and set the MIME Type appropriately
if(blobdata!=null){

res.setContentType("image/gif");
// throw throw the image
ServletOutputStream out = res.getOutputStream();

long lHtmlLength = blobdata.length();

long l = 1;
byte iIEHTMLContent[];

while (l < lHtmlLength) {
iIEHTMLContent = blobdata.getBytes(l, 2048);
out.write(iIEHTMLContent);
l = l + 2048;
}//while

ors.close();
out.close();
}//if

} catch (SQLException e) {
new FatalEvent("SISWebLog", Counter.getNext(), "CSSISPImageServlet", "doPost"
, e.toString());
} catch (Exception e1) {
new FatalEvent("SISWebLog", Counter.getNext(), "CSSISPImageServlet", "doPost"
, e1.toString());

} finally {
try {

//close resultset
if(ors!=null){
ors.close();
}//if

//close connection
if (con != null) {
con.close();
dbConnection.freeConnection();
dbConnection.removeConnection();
}//if
} catch (SQLException ignored) {
new FatalEvent("SISWebLog", Counter.getNext(), "CSSISPImageServlet",

"doPost"
, ignored.toString());
}//catch
}//finally
}


These are the following problems I face.
1) The page gets timed out.
2) The images are downloaded sequentially. ie: after the first image is downloaded, the request

for second goes.
3) I get java.net.SocketException.

Can any one help me by telling me the difference in behaviour, when we give physical filenames as

image src and Servlets as image src.
Moreover does any one knows why the page gets timed out.


thanks
munira

   <<Less

Re: Image Source in a html, pointing to a Servlet.

Posted By:   faisal_parwani  
Posted On:   Monday, April 16, 2001 10:10 PM

when we are giving img src url as physical url its mean
that image is already presented on that url and it just
fetches that img file,
while in servlet image is either created or read fro m some
source, and send to the browser as stream.
Here in your code i could not able to uner stand how image is
read from database.
that blob data should be converted into gif first and then
should be send to browser.
for image conversion u can search an gif encoder.
About | Sitemap | Contact