迭代一个hashmap struts 1.x.

时间:2015-08-04 11:54:37

标签: java jsp jsp-tags struts-1

Sturts 1.x框架。我正在尝试迭代哈希映射。 “blockIdCountMap”是由“EquipmentCharacteristicFormBean”bean中的getter方法返回的hashmap。

jsp页面中的代码。

<logic:iterate name="EquipmentCharacteristicFormBean" id="blockIdCountMap" >
        <bean:write name="blockIdCountMap" property="key"/>
        <bean:write name="blockIdCountMap" property="value"/>
</logic:iterate>

ERROR:

Aug 4, 2015 5:18:43 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet login threw exception
javax.servlet.jsp.JspException: Cannot create iterator for this collection
    at org.apache.struts.taglib.logic.IterateTag.doStartTag(IterateTag.java:310)
    at org.apache.struts.taglib.nested.logic.NestedIterateTag.doStartTag(NestedIterateTag.java:123)
    at org.apache.jsp.website.equipment.equipmentCharacteristic_jsp._jspService(equipmentCharacteristic_jsp.java:224)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
    at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:451)
    at org.apache.struts.action.RequestProcessor.processActionForward(RequestProcessor.java:401)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1420)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:520)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:646)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:436)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:374)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:302)
    at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1056)
    at org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:451)
    at org.apache.struts.action.RequestProcessor.processActionForward(RequestProcessor.java:401)
    at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
    at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1420)
    at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:520)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.railsync.command.filter.RequestMonitorFilter.doFilter(RequestMonitorFilter.java:102)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.railsync.command.filter.GZIPFilter.doFilter(GZIPFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:620)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:655)

1 个答案:

答案 0 :(得分:2)

blockIdCountMap是getter方法返回的HashMap对象意味着您必须将property属性赋予id,因为id表示您指的是变量

使用以下代码:

<logic:iterate name="EquipmentCharacteristicFormBean" property="blockIdCountMap" id="map">
     <bean:write name="map" property="key"/>
     <bean:write name="map" property="value"/>
</logic:iterate>