1

我的图像名称 A(1),A(2).......A(n) 被放入根/文件夹。Tomcat 提示,图片无法显示,有错误,如果我们在地址栏中给出图片 URL... 这是 Show.jsp 页面。

<%

        String x = getServletContext().getContextPath().toString();


        x=request.getServerName();
        int y=request.getServerPort();
        x=z+""+y+dir;



        File f = new File(x);

        if (f.isDirectory()) {
            String[] fileList = f.list();
            //out.println("Directory of " + x + "<br>");
            for (int i = 0; i < fileList.length; i++) {

                File f1 = new File( fileList[i]);
                if (f1.isDirectory()) {

// to Show it is a directory
out.println(fileList[i] + " is a Directory<br>");
                } else {

                    out.print("<br>");

        out.print( fileList[i]); // file name list
    %>

    <img src="<%out.print(fileList[i]);%>" /> // image URL Dynamically

    <br />

    <%
        }
            }
        } else {
            out.println("<BR>");
        }
    %>
4

0 回答 0