Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 169
  • Last Modified:

how to display some pics in only one page. which saved in oracle .

to all :
how to display some  pics in only one page. which saved in oracle .
  i use this code :
PreparedStatement sql=con.prepareStatement("select * from blob_test WHERE
rno =13" );
ResultSet rs = sql.executeQuery();
rs.next();
InputStream in = rs.getBinaryStream("photo");
response.reset();
response.setContentType("image/bmp");
byte[] b = new byte[1024*1024];
int len;
while((len=in.read(b)) >0)
response.getOutputStream().write(b,0,len);
in.close();
rs.close();


but it just display only one photo in whole page and i want to the page
display more content,such as
other pictures,and some words.

how to control ? please give me some code or advice,
       with many thanks

handsome1234
0
handsome1234
Asked:
handsome1234
1 Solution
 
objectsCommented:
Keep what you've got and modify it so it gets the photoid as a request parameter, and create a new page which uses it to display all your photos.

<%
PreparedStatement sql=con.prepareStatement("select rno from blob_test");
ResultSet rs = sql.executeQuery();
while (rs.next())
{
%>
<img src="GetPhotoServlet?id=<%= rs.getObject("rno") %>" >
<%
}
%>

0
 
kennethxuCommented:
in your servlet use this:

String strRno = request.getParameter( "rno" );
int rno = 0;
if( strRno != null ) {
   try { rno = Integer.parseInt( strRno ); }
   catch( NumberFormatException e ) { strRno = null; }
}
if( strRno == null ) {
   response.sendError( HttpServletResponse.SC_NOT_FOUND );
   return;
}
PreparedStatement sql=con.prepareStatement("select photo from blob_test WHERE
rno = ? );
sql.setInt( 1, rno );
ResultSet rs = sql.executeQuery();

then create any jsp or html page that includes those lines:
<html>
....
<img src="urlToYourServlet?rno=13" >
<img src="urlToYourServlet?rno=14" >
<img src="urlToYourServlet?rno=5" >
<img src="urlToYourServlet?rno=13" >
.....
</html>
0
 
objectsCommented:
thats what I just said :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
handsome1234Author Commented:
ok,thanks ,
but i didnot want to create more pages for that

can i contol more photos display just in only one page ?
as i recently asked ?
0
 
objectsCommented:
> can i contol more photos display just in only one page ?

no. a servlet can only return a single image.
0
 
syd108Commented:
The way i have dealt with this in the past is by just storing the path to the image(on web server) in the database and by simply using it in the src of the img tag.

regards
syd
0
 
girionisCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to objects

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now