Solved

add images to jsp page dynamically

Posted on 2009-05-09
2
5,006 Views
Last Modified: 2012-05-06

add dynamic content to jsp page
Bookmark:
Question: hi i want to add images to my jsp page dynamically..
<%
     int count=new File(filepath).listFiles().length;
%>
think from the above code i get count value as 10.now i want to add 10.jpg to my jsp page
by the following code.(now i want to add a image to my jsp page with respective the count value)
<table>
 <tr>
  <td><img src="images/ln/headings/"+count.jpg+""></td> (all my jpg files in images/ln/headings)
 </tr>
</table>
if the count value is 9, it has to add 9.jpg to my jsp page.
so, plz observe the above html code and correct that code and give correct one.
0
Comment
Question by:haneefnb
2 Comments
 
LVL 10

Accepted Solution

by:
Chad Smith earned 500 total points
ID: 24344359

<table>
 <tr>
  <td><img src="images/ln/headings/<%= count %>.jpg"></td> (all my jpg files in images/ln/headings)
 </tr>
</table>

Open in new window

0
 
LVL 27

Expert Comment

by:rrz
ID: 24344700
Please try this sample JSP.
<%@ page import="java.io.*" %>
<%
  String dirPath ="/images/ln/headings";
  String realPath = application.getRealPath(dirPath);
  File dir = new File(realPath);
  String[] list = dir.list(new FilenameFilter(){
                                       public boolean accept(File dir, String name){
                                                               return name.endsWith(".jpg");
                                       }
                             });
 
%>
<html>
<body>
<% 
  for(String imagePath:list){
    out.print("<img src=\"" + request.getContextPath() + dirPath + "/" + imagePath + "\"/>");
  }
%>
</body>
</html>

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Obtaining data on ASP 8 28
100% tall div not scrollable on iPhone 3 20
Html value of radio 14 27
I need help changing the colour of this image rollover please? 3 11
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to dynamically set the form action using jQuery.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question