foreach循环在jsp page.help中的javascript中无效。提前任意body.thanks。
<script type="text/javascript">
var lineCoordinates = [
< c:forEach items = "${mapBean.googleMapLocations}" var = "googleLocation" varStatus = "status" >
['${googleLocation.latitude}', '${googleLocation.longitude}']
< c:if test = "${!status.last}" >
,
< /c:if>
< /c:forEach>
];
alert(lineCoordinates);
</script>
mapBean managedbean:
public java.util.List<Components> getGoogleMapLocations() {
System.out.println("entered");
SessionFactory sf = HibernateUtil.getSessionFactory();
Session sess = sf.openSession();
Query q = sess.createQuery("from Components");
java.util.List l = q.list();
Iterator it = l.iterator();
while (it.hasNext()) {
Components cmp = (Components) it.next();
System.out.println("Latitude" + cmp.getLatitude() + "longitude" + cmp.getLongitude() );
}
sess.close();
return l;
}