2012-08-30 177 views
0
HashMap<String, HashMap<Integer, String>> hMap = new HashMap<String, HashMap<Integer,String>>(); 

HashMap<Integer, String> xx = new HashMap<Integer, String>(); 
xx.put (1, "ABC"); 
xx.put (2, "def"); 

HashMap<Integer, String> yy = new HashMap<Integer, String>(); 
yy.put (1, "ABC"); 
yy.put (2, "def"); 

hMap.put ("20120826", xx); 
hMap.put ("20120827", yy); 

request.setAttribute("hoursByProjectByDay", hMap); 

ArrayList<String> displyDtArr = new ArrayList<String>(); 
displyDtArr.add("20120826"); 
displyDtArr.add("20120827"); 
request.setAttribute("displayDates", displyDtArr); 

ArrayList<Integer> projects= new ArrayList<Integer>(); 
projects.add(1) 
projects.add(2); 
request.setAttribute("projects", projects); 


     <c:forEach var="pl" items="${projects}"> 
<c:forEach var="displayDt" items="${displayDates}"> 
    <c:forEach var="hoursByProjByday" items="${hoursByProjectByDay[displayDt]}"> 
      <c:set var="userHour" value="${hoursByProjByday[pl]}"/> 

     </c:forEach> 
    </c:forEach> 
</c:forEach> 

它提供了以下錯誤:JSTL問題,嵌套HashMap的

堆棧跟蹤:

org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:524) 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:435) 
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) 
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 
edu.uchospitals.timetrack.FrontController.dispatch(FrontController.java:121) 
edu.uchospitals.timetrack.FrontController.processRequest(FrontController.java:116) 
edu.uchospitals.timetrack.FrontController.doPost(FrontController.java:152) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:710) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 

root cause 
javax.el.PropertyNotFoundException: Property '1' not found on type java.util.HashMap$Entry 
javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:193) 
javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:170) 
javax.el.BeanELResolver.property(BeanELResolver.java:279) 
javax.el.BeanELResolver.getValue(BeanELResolver.java:60) 
javax.el.CompositeELResolver.getValue(CompositeELResolver.java:53) 
org.apache.el.parser.AstValue.getValue(AstValue.java:97) 
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186) 
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:923) 
org.apache.jsp.WEB_002dINF.jsp.main_jsp._jspx_meth_c_005fset_005f0(main_jsp.java:548) 
org.apache.jsp.WEB_002dINF.jsp.main_jsp._jspx_meth_c_005fforEach_005f5(main_jsp.java:513) 
org.apache.jsp.WEB_002dINF.jsp.main_jsp._jspx_meth_c_005fforEach_005f4(main_jsp.java:471) 
org.apache.jsp.WEB_002dINF.jsp.main_jsp._jspx_meth_c_005fforEach_005f1(main_jsp.java:338) 
org.apache.jsp.WEB_002dINF.jsp.main_jsp._jspService(main_jsp.java:138) 
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393) 
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320) 
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 
edu.uchospitals.timetrack.FrontController.dispatch(FrontController.java:121) 
edu.uchospitals.timetrack.FrontController.processRequest(FrontController.java:116) 
edu.uchospitals.timetrack.FrontController.doPost(FrontController.java:152) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:710) 
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 

任何想法如何照顧這?

回答

0

你是迭代一個集合,那就是問題

嘗試,

<c:forEach var="project" items="${projects}"> 
    <c:forEach var="displayDt" items="${displayDates}"> 
     <c:forEach var="userHours" items="${hoursByProjectByDay[displayDt][project]}"> 
      <br/>${userHours} 
     </c:forEach> 
    </c:forEach> 
</c:forEach>