Solved

add images to jsp page dynamically

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

747 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

11 Experts available now in Live!

Get 1:1 Help Now