Hey all,
I posted few days back about displaying all .jpeg files inside a folder in a table...I figured out partially how to do that with JSP..By Partially I mean that I am able to count the number of files inside the folder, and then run a For loop based on the number of files..But now the problem is if I directly hardcode the name of the image say 1.jpg it displys that file for how many ever times the loop is running...
For example my folder has 2 images 1.jpg and 2.jpg..the name of the folder is pictures inside C drive..the code below counts the number of files in pictures folder, which is nothing but 2..then runs the loop for 2 times...As you can see, I have directly given the name of the img source as 1.jpg..That makes the 1.jpg to appear twice on my webpage..But now how do I make it dynamic and make both the image files appear(rather than 1.jpg appearing twice, I want 1.jpg and 2.jpg appear once each)??Should I do this
<img src="pictures/<%j;%>.jpg" width="242"/> Any help wud be appreciated..

<table>
    <%  string dir = @"C:pictures\\1870";
        string[] files;
        int files_count,count;
        files =System.IO.Directory.GetFiles(dir);
        files_count = files.Length;
        string next = (files_count + 1) + ".jpg";
        count = files_count;
        //TextBox1.Text = dir;
        for (int j = 1; j <= count; j++)
        {
   %>
    <tr>
    <td>
    <img src[B]="pictures/1.jpg"[/B]width="242"/></td>
    </tr>
 <% }%>
    </table>

Thanks
Ani

That should work.

You might need to use

out.print(j);

for some reason if I use scripts in <img src="<!--scripts-->"> , it doesnt work...anyone knows why...It just appears as a black text...looks so obvious that its not correct..if i even try to declare some variable say string g; even the datatype "string" is all plain and black, when it was supposed to be blue..Eg <img src="<%string g;%>"/>.hmmm...any help wud be appreciated...
Ani

That should work.

You might need to use

out.print(j);

what about this

<td>
<img src="<%=j%>" />

Ah awesome....!it worked..Hey thanks Keith...

Ani

what about this

<td>
<img src="<%=j%>" />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.