?
Solved

add images to jsp page dynamically

Posted on 2009-05-09
2
Medium Priority
?
5,072 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
Chad Smith earned 2000 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 28

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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
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…
Suggested Courses

764 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