Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

add images to jsp page dynamically

Posted on 2009-05-09
2
Medium Priority
?
5,100 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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

610 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