The moose likes JSP and the fly likes Displaying images that match database records Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Displaying images that match database records" Watch "Displaying images that match database records" New topic

Displaying images that match database records

shuzo monsoon
Ranch Hand

Joined: Feb 11, 2004
Posts: 54
I have created a page which allows users to select a radio button which takes them to a page which displays details of the particular record they have selected. Though I can get the specific details of that record from the database I would like to be able to get a corresponding image for that record also. Can anyone think of a way which I can assign indexes for a particular record to an image? I have tried using an if-else loop to see what the id for the chosen record is and then tried to display the appropriate image, but this doesn't work.
Any help would be much appreciated!
Oliver Moore
Ranch Hand

Joined: Mar 04, 2003
Posts: 44
If your image names correspond to the index number of your record, why not use something like:
<img src="/images/<%= indexNumber %>.jpg">
on the page where you are displaying the record the users has selected.
Obviously, there are a number of ways you can pull the index number from the record set you return rather than <%= indexNumber %>.
If your image name does not correspond to the index number, why not just store the file name of the image you want associated with the record in the database. You can the use the stored filename in a similar way to the above example.
Hope this is of help...

shuzo monsoon
Ranch Hand

Joined: Feb 11, 2004
Posts: 54
That makes sense, thanks a lot Ols. The name of my images is not the same as the index numbers but I think I will make them the same and it just might work. Thanks again.
Consider Paul's rocket mass heater.
subject: Displaying images that match database records
Similar Threads
Will AJAX work with images?
Need some help regarding MVC arcitecture
PLEASE HELP????? jsf + form population
online shopping
Can I use single servlet and a single model to satisfy two functionalities.