// 到本地服务器的图片目录中把所有图片遍历出来,然后拼接成<img>输出
// 一个技术:如何访问WebRoot下的资源文件
// File dir=new File(".");//这个目录是:Tomcat/bin
ServletContext ctrx = getServletContext();
String path1 = ctrx.getContextPath();// 项目名而且是活的
String path2 = ctrx.getRealPath("/img");// 绝对路径:D:\apache-tomcat-7.0.30\webapps\servletDemo3\imgs
File dir = new File(path2);
String dirs[] = dir.list();
for (String dira : dirs) {
String img = "<img width='200px' height='200px' src='img/" + dira
+ "'/>";
out.println(img);
访问Webroot下的资源文件
最新推荐文章于 2020-08-19 16:58:38 发布