列表无法在jsp中解析

时间:2017-08-03 07:20:27

标签: java jsp import

下面的代码用于显示来自服务器文件夹的图像,但列表显示无法解析的类型。使用servlet代码将图像上传到文件夹" private static final String UPLOAD_DIRECTORY =" upload""现在我希望将所有图像显示到jsp页面。请帮忙

<%@ page import ="java.io.*"%>;
<%@ page import ="java.io.File.*"%>;
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import ="java.util.ArrayList.*"%>
<%@ page import ="java.util.List.*"%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>File Upload Example</title>
    </head>
    <body> 
        <div id="result">
            <h3>${requestScope["message"]}</h3>
        </div>

        <%
            List imageUrlList = new ArrayList(); //List cannot be resolved type
            File imageDir = new File("Upload");
            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);
        %>
    <c:forEach var="img" items="${imageUrlList}">  
        <img src="${imageUrlList}"/>  
    </c:forEach>

</body>
</html>

1 个答案:

答案 0 :(得分:3)

导入错误,List / ArrayList是类而不是包,因此您需要删除。*

<%@ page import ="java.util.ArrayList"%>
<%@ page import ="java.util.List"%>