Java 如何在jsp页面中显示特定文件夹中的所有图像?
我有一个文件夹,其中包含多个图像,我想在我的jsp页面中显示所有图像。我在jsp页面中尝试以下代码Java 如何在jsp页面中显示特定文件夹中的所有图像?,java,jsp,liferay,Java,Jsp,Liferay,我有一个文件夹,其中包含多个图像,我想在我的jsp页面中显示所有图像。我在jsp页面中尝试以下代码 <img src="<%=request.getContextPath() %>/uploadFolder/poll1.jpg" width="114" height="110" style="float: left;"> <h1> Images </h1> /uploadFolder/poll1.jpg” width=“114”
<img src="<%=request.getContextPath() %>/uploadFolder/poll1.jpg"
width="114" height="110" style="float: left;">
<h1>
Images
</h1>
/uploadFolder/poll1.jpg”
width=“114”height=“110”style=“float:左侧;">
图像
我在uploadFolder中有10多个图像,我想在jsp页面中显示所有图像,请帮助我如何做到这一点
File f = new File("/uploadFolder/");
File[] list = f.listFiles();
您将获得上载文件夹中所有文件的列表-
你只需要像这样循环-
for(int i = 0 ; i < list.length ; i++){
File jpg = list[i];
// use this file object to create img tag's in your jsp
}
for(int i=0;i
有关的更多信息请在jsp页面上使用以下代码:
File folder = new File("d:\\Reports"); //your path
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
File folder=新文件(“d:\\Reports”);//您的路径
File[]listOfFiles=folder.listFiles();
for(int i=0;i
在html页面中:
<a href="servlet&filename=<%=listOfFiles[i].getName()%>">Download</a>
}}
}}
我已经使用
标记显示了您可以在表或
标记中显示它。构建要显示的文件名列表
List imageUrlList = new ArrayList();
File imageDir = new File("/myapp/images");
for(File imageFile : imageDir.listFiles()){
String imageFileName = imageFile.getName();
// add this images name to the list we are building up
imageUrlList.add(imageFileName);
}
request.setAttribute("imageUrlList", imageUrlList);
然后在jsp上为每个文件显示一个
标记
<c:forEach var="img" items="${imageUrlList}">
<img >
</c:forEach>
如何在jsp页面中编写文件?请提供完整的代码以及我不知道如何编写的语法