【发布时间】:2011-06-10 04:57:47
【问题描述】:
我正在尝试编写一个显示多台服务器备份状态的备份仪表板。这个想法是显示一个带有 JSP 的表,该表在列中具有最近几天的日期,在行中具有服务器名称。在这个穷人的表格中,我写了是/否值。
+------------+------------+------------+------------+
+ Host Name | 2011-06-10 | 2011-06-09 | 2011-06-08 |
+------------+------------+------------+------------+
| web01 | Y | Y | N |
+------------+------------+------------+------------+
| web02 | Y | Y | Y |
+------------+------------+------------+------------+
每台服务器都有自己的备份并将状态保存到 Amazon SimpleDb 中,我编写了一个 Java 方法来检索最近几天的这些信息,签名如下:
/**
* List MySQL backups of the last howManyDays days. It starts from today
* included at index 0 and goes back in the past until we have a list of
* howManyDays days, even if some day doesn't have any data. Return a list of
* dates, each of which contains a list of backup jobs executed by servers in
* that day.
*
* @param howManyDays
* how many days of backup to show
* @return a Map where each key is the date in ISO format (2011-06-10) and each
* element is a backupJob which is represented by a Map where the key is
* the server name (ex. web01, web01) and the value is "Y" if all was
* fine, otherwise it contains the error message.
*/
public Multimap<String, Map<String, String>> listMysqlBackups(int howManyDays);
Multimap 是 Google Guava Multimap,因为我每天有多个备份。示例输出:
{2011-06-10=[{web06=Y}, {web05=Y}], 2011-06-08=[{web05=Y}, {web06=Y}],
2011-06-09=[{web05=Y}, {web06=Y}], 2011-06-07=[{web05=Y}, {web06=Y}]}
我不知道如何在 JSP 中使用这些信息。我试过 foreach:
<c:forEach items="${backups}" var="backup" varStatus="backupId">
${backup.key}
</c:forEach>
答案是:
javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Don't know
how to iterate over supplied "items" in <forEach>
现在我在想,如果我用一个过于复杂的返回值来打自己的脚,我是否应该返回一个简单的 HashMap ArrayList,其中每个 HashMap 都包含所有需要的信息(日期、主机名、消息)。如果你们认为这是一种更好的方法,我重写提取数据的 Java 方法没有任何问题,但是现在每个单元都需要遍历所有 ArrayList 以获取元素(这可能没问题,因为 6 个服务器乘以 7 days 只有 42 个元素)。
您将如何解决这个问题?
【问题讨论】: