如何在jsp页面的selector标签中显示来自servlet的Date列表

时间:2016-01-11 11:36:51

标签: java jquery html jsp servlets

我正在尝试动态生成JSP中没有重复项的日期列表,以显示在选择器标记中。

在我的servlet类中:

query = " SELECT * FROM visits";
prepStatement = connection.prepareStatement(query);

results = prepStatement.executeQuery();
Set<Date> vdates = new HashSet<>();
while(results.next()){
    vdates.add(results.getDate("date"));                
}
Date[] dates = vdates.toArray(new Date[vdates.size()]);
out.println(vdates);
request.setAttribute("dates", dates);
RequestDispatcher dispatcher = request.getRequestDispatcher("/js/selectorJSP.jsp");
dispatcher.forward(request, response);

在我的selectorJSP文件中:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Selector Page</title>
    <script src="js/jquery-2.1.4.min.js"></script>
    <script>
    </script>
</head>
<body>
    <h1>Hello World!</h1>
    <select>
        <option value="AllRecords">${dates[0]}</option>
    </select>
    <input type="button" onclick="" value="Download">
</body>
</html>

结果是它只是显示一个空字段,我试图显示一个以确保它有效并循环显示选择器中的所有可用日期但不可用。

0 个答案:

没有答案