<bean id="propertyData"
class="org.springframework.beans.factory.config.PropertiesFactoryBean"
lazy-init="false">
<property name="mydata">
<value>classpath:external-data.properties</value>
</property>
</bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
<property name="exposedContextBeanNames">
<list><value>propertyData</value></list>
</property>
</bean>
Run Code Online (Sandbox Code Playgroud)
使用上面的代码片段,我可以加载属性文件并在jsp中访问该文件。并在jsp中使用以下语法成功通过键访问值
<option value='${propertyData.usa}'>${propertyData.usa}</option>
Run Code Online (Sandbox Code Playgroud)
现在,我需要使用jstl或其他方式遍历jsp中的所有属性键,以使用这些键的值填充html下拉列表。
以下不适用于我。
<core:forEach var="listVar" items="${propertyData}">
<option value ="10"><core:out value="${listVar.attribute}"/></option>
</core:forEach>
Run Code Online (Sandbox Code Playgroud)
错误是:
javax.el.PropertyNotFoundException: Property 'attribute' not found on type java.util.Hashtable$Entry
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
Run Code Online (Sandbox Code Playgroud)
请更正我要去的地方。
如何<Integer, List<ResponseInfo>>使用<c:forEach>JSTL标记在JSP中迭代map,然后使用另一个for循环迭代该列表?
如果您想查看代码,请告诉我.
从控制器我回来了
return new ModelAndView("reviewAudit","responseForm",responseForm);
其中responseForm包含一个地图:
private Map<String, List<ResponseInfo>> resInfoMap;
这是我的JSP代码:
<div class="panel-body">
<div class="panel-group" id="accordion">
<c:forEach items="${responseForm.resInfoMap}" var="responselist">
<div class="panel panel-primary">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" class="">Topic1</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" aria-expanded="true">
<div class="panel-body">
<table>
<c:forEach items="${responselist}" var="response1">
<tr>
<td>
<p>
<span style="font-size: 13px; font-weight: bold;">Q:</span>
${response1.auditQuestion}
</p>
</td>
<td>
<p>
<span style="font-size: 13px; font-weight: bold;">Ans:</span>
${response1.auditResponse}
</p>
<p>
<span style="font-size: 13px; …Run Code Online (Sandbox Code Playgroud) 我在两个叠加的JSTL中使用了二维arraylist <c:forEach>:
<select multiple size="30">
<c:forEach var="uri" items="${defaultResult}" varStatus="iterator">
<c:forEach var="cate" items="${defaultResult[iterator.index]}">
<option value="${defaultResult[iterator.index][0]}"> ${cate}[1]</option>
</c:forEach>
</c:forEach>
</select>
Run Code Online (Sandbox Code Playgroud)
但索引似乎不起作用,例如返回${cate}[1]的值是后跟任何维度的所有值[1]
如果您有任何想法来解决我的问题,那将会很有帮助.
我有一个resultSet,每次都有不同数量的结果,需要在我的页面上多次使用.目前,我将结果存储在ArrayList中,并计划循环遍历arraylist.我不知道有多少行所以这就是我到目前为止所拥有的:
while (result.next()) {
tmpTerms.add(term = (((result_data = result.getObject("val_internal_code"))==null || result.wasNull())?" ":result_data.toString()));
tmpTerms.add(desc = (((result_data = result.getObject("val_external_representation"))==null || result.wasNull())?" ":result_data.toString()));
tmpTerms.add(sorter = (((result_data = result.getObject("sorter"))==null || result.wasNull())?" ":result_data.toString()));
tmpTerms.add(sDate = (((result_data = result.getObject("sDate"))==null || result.wasNull())?" ":result_data.toString()));
}
Run Code Online (Sandbox Code Playgroud)
好的,所以当我运行它时,系统打印:代码:
[2011SP, Spring 2011, 1, 11-15-2010, 2011SU, Summer 2011, 1, 01-15-2011, 2011FL, Fall 2011, 1, 04-01-2011, 2010Q2, CE Qtr 2 2010 Dec - Feb, 2, 08-01-2010, 2011Q3, CE Qtr 3 2011 Mar - May, 2, 11-01-2010, 2011Q4, CE Qtr 4 2011 Jun - …Run Code Online (Sandbox Code Playgroud) 我对jsp没有多少经验.在java中我能做到,但打开一个块<%%>并不好