JSTL和哈希图不起作用 [英] JSTL and hashmap not working

查看:60
本文介绍了JSTL和哈希图不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在servlet中,我有:

In a servlet I have:

HashMap eventsByDayNo = new HashMap();
eventsByDayNo.put (new Integer(12), "day 12 info");
eventsByDayNo.put (new Integer(11), "day 11 info");
eventsByDayNo.put (new Integer(15), "day 15 info");
eventsByDayNo.put (new Integer(16), "day 16 info");

request.setAttribute("eventsByDayNo", eventsByDayNo);
request.setAttribute("daysInMonth", new Integer(31));

在一个jsp中,我有:

And in a jsp I have:

<c:forEach var="dn" begin="1" end="${daysInMonth}" step="1" varStatus="status">
  Day Number=<c:out value="${dn}" /> Value=<c:out value="${eventsByDayNo[dn]}" /><br>
</c:forEach>

上面的JSTL可以正常工作,但是如果我尝试抵消日期编号<c:out value="${eventsByDayNo[dn+3]}" /> 没有哈希表项没有被打印.关于为什么不的任何答案?

The above JSTL works fine, but if I try to offset the day number <c:out value="${eventsByDayNo[dn+3]}" /> none of the hashmap entries are not printed. Any answers as to why not?

以上只是我的实际应用的概念证明.

The above is just a proof of concept for my real application.

推荐答案

我的猜测是dn+3具有类型java.lang.Double,而不是java.lang.Integer(您可能会期望).

My guess is that dn+3 has type java.lang.Double, not java.lang.Integer (which you may expect).

<ul>
<c:forEach var="dn" begin="1" end="${daysInMonth}" step="1">
  <li>
    <c:set var="dnplus3" value="${dn+3}" />
    dn=<c:out value="${dn}" />
    dnplus3=<c:out value="${dnplus3}" />
    class=<c:out value="${dnplus3.class.name}" />
  </li>
</c:forEach>
</ul>

这篇关于JSTL和哈希图不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆