2012-03-20 180 views
1

使用JSTL和Spring時遇到問題......它不允許我遍歷我的列表。ForEach不適用於列表

這是我的看法......

<html> 
<body> 

    // This prints fine 
    <h2>${profileList}</h2> 


    // this doesn't 
    <c:forEach var="x" items="${profileList}" > 
     <c:out value="${x}"/> 
     <br /> 
    </c:forEach> 
</body> 
</html> 

這裏是我的控制器......

@RequestMapping("/")  
    public ModelAndView welcomeHandler() throws Exception { 
     JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); 

     List profileList = analyticsManager.getProfiles(); 

     ModelAndView model = new ModelAndView("HelloWorldPage"); 
     model.addObject("msg", Integer.toString(profileList.size())); 
     model.addObject("profileList", profileList); 

    return model; 
    } 

這裏是構建列表中的代碼...

public List<String> getProfiles() throws Exception { 
     List profileList = new ArrayList<String>(); 

     Profiles profiles = analytics.management().profiles().list("~all", "~all").execute(); 

     for (Profile profile : profiles.getItems()) { 
      profileList.add(profile.getId()); 
     } 

     return profileList; 
    } 

回答

4

你在使用之前需要聲明JSTL。將其添加到JSP的頂部:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
+0

賓果!謝啦! – gshauger 2012-03-20 20:14:17