我试图找出如何迭代使用getter方法将字符串作为键和Object的ConcurrentHashMap。
以下是将对象作为值存储在地图中的类。
public class ServiceStats {
public int unprocessedItems;
public int processedItems;
/**
* @return the unprocessedItems
*/
public int getUnprocessedItems() {
return unprocessedItems;
}
/**
* @param unprocessedItems the unprocessedItems to set
*/
public void setUnprocessedItems(int unprocessedItems) {
this.unprocessedItems = unprocessedItems;
}
/**
* @return the processedItems
*/
public int getProcessedItems() {
return processedItems;
}
/**
* @param processedItems the processedItems to set
*/
public void setProcessedItems(int processedItems) {
this.processedItems = processedItems;
}
}
Servlet正在像这样向JSP发送数据。
@Override
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
ConcurrentHashMap<String, ServiceStats> serviceStatsMap = stats.getServiceStats();
request.setAttribute("stats", serviceStatsMap);
request.getRequestDispatcher("WEB-INF/jsp/stats.jsp").forward(request, response);
}
迭代应该是这样的:
<c:forEach var="entry" items="${stats}">
${entry.key}, ${entry.value.getvaluefromgettermethod}
</c:forEach>
如何访问map的值,然后访问该对象中的getter方法?
我是否必须在JSP中导入我的类,或者这是不必要的?
<%@ page import="com.company.ServiceStats"%>
答案 0 :(得分:1)
如果要访问ServiceStats
类型对象的属性${entry.value.unprocessedItems}
,因为它具有正确的getter,dataGridView1.DataSource = dpep.Tables["IMAGERY_DIAGNOSTIC"];
应该足够,也不需要导入。