aspose file tools*
The moose likes JSP and the fly likes image display in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "image display in JSP" Watch "image display in JSP" New topic
Author

image display in JSP

venkatesh pendharkar
Ranch Hand

Joined: Apr 29, 2006
Posts: 106
Hi
I am trying to make an online photoDatabase in which there will be a gallary which will contain thumbnails of all the images.The code for showing thumbnails will be something like this:

<%!String s[]=new String[5];
%>
<%
s[0]="images/one.JPG";
s[1]="images/two.JPG";
s[2]="images/three.JPG";
s[3]="images/four.JPG";
s[4]="images/five.JPG";
for(int i=0;i<5;i++)
{
%>
<A HREF="photo.jsp"><IMG SRC="<%=s[i]%>" Width="164" Height="110"
Alt="info" Border="0"></a>
<br>
<%}%>

Here String array contains "url"s for different images which actually will be selected from the database as per the category selected by the user.Now when the user clicks on a particular photo then photo.jsp will be called where large image of the thumbnail will be shown.But i dont understand how "photo.jsp" will know which thumbnail was selected so that it can retrieve the larger image for displaying.I want to know if there is any way by which we can send the parameter to the photo.jsp through href.
Please hepl me in this!!! Please let me know if this can be designed in some other way.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61598
    
  67

First things first:

<%!String s[]=new String[5];
%>


That is a problem waiting to happen. You do realize that by using the <%! %> construct that your string is no longer thread safe?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
venkatesh pendharkar
Ranch Hand

Joined: Apr 29, 2006
Posts: 106
HI Mr Bibeault,
Thanks for your response.I understand that by writing String in <%!%> construct it becomes instance variable for this JSP so it wont be thread safe,we should write in within scriplet itself.But at this stage i am not thinking about coding details ,I am just in designing phase.So currently it will be great help if you can help me in designing this & help me out on the problem that i have mentioned.
Thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61598
    
  67

Originally posted by venkatesh pendharkar:
But at this stage i am not thinking about coding details ...


That is an attitude that will get you into big trouble. Problems such as you have created here are easy to avoid and have a way of causing major problems later when they accidentally remain uncorrected.

Always write code, even test or prototype code, properly. Otherwise, you are just asking for headaches!
[ February 01, 2007: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61598
    
  67

With regards to design, I wouldn;t do this whole thing in JSP, but rather with a combination of JSP and Javascript.

You know all the file names up front, and all you need to do is to switch out the src of the <img> tag in order to change which image is shown, so there's no need to go back to the server every time the image is to be changed.

I'd use JSP to write an HTML page that contains all the information about the images in Javascript structures, and then write a small script to handle swapping the src attribute upon user clicks.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: image display in JSP