Solved

add images to jsp page dynamically

Posted on 2009-05-09
2
4,987 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Mobile menu navigation , its html and css 6 54
Synchronizing CSS load 3 29
AngularJS Page Control Understanding 5 39
Split in Javascript 5 30
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now