2015-01-21 76 views
-1

我将两个列表添加到一个Map map = new HashMap()中。我想使用JSTL从获得在JSP页面中值 我contriller是如何使用JSTL迭代Map <String,List> map = new HashMap <String,List>()在jsp页面中使用JSTL

 @RequestMapping("/addprogram") 
public ModelAndView thematicday() 

    { 
    Map<String, List> map = new HashMap<String, List>(); 
    try{ 
     List<Themes> theme=dataServices.getTheme(); 
     List<String> themeday=dataServices.getThematicDate(); 

     map.put("theme", theme); 
     map.put("themeday", themeday); 
    } 
    catch(Exception e) 
    { 
     e.printStackTrace(); 
    } 
    return new ModelAndView("thematicday","map",map); 
    } 

我exctract第一个列表

<c:forEach var="events" items="${map.theme}"> 
          <option value="${events.themeid}">${events.themename}</option> 

但我不知道如何从字符串列表exctract值

daoImpl中的第二个列表

@SuppressWarnings("unchecked") 
@Override 
public List<String> getDate() { 
    List<ThematicDay> Themedate = null; 
    session=sessionFactory.openSession(); 
    tx=session.beginTransaction(); 
    Query query = session.createQuery("select a.themedate,a.thematicdayid from tableone a where a.thematicdayid in(SELECT thematicdayid FROM tabetwo GROUP BY thematicdayid HAVING COUNT(*) < 3)"); 
    List<Object> result = (List<Object>) query.list(); 

    List<String> strings = new ArrayList<String>(); 
    for (Object object : result) { 
     strings.add(object != null ? object.toString() : null); 
    } 
    System.out.println("\n\n *&*&*&* "+strings); 
    for(int i=0; i<strings.size(); i++){ 
     String stringArray = strings.get(i); 
     System.out.println("\n\n *&*&*&* "+stringArray); 


    } 
    tx.commit(); 
    session.close(); 
    return strings; 
} 

我们E该代码来获得该列表

<c:forEach var="Date" items="${map}"> 
        <c:if test="${Date.key == 'themeday'}"> 
        <div class="bottom-article"> 
         <ul class="meta-post"> 
          <li><a href="#" class="tl_1"> ${Date.value[0]} </a></li> 
          <li><a href="#" class="tl_2">${Date.value[1]} </a></li> 
         </ul> 
         </div> 
         </c:if> 
         </c:forEach> 

但得到这样

[Ljava.lang.Object;@762b0f 
[Ljava.lang.Object;@4f983 
+1

你需要观察'List '你得到了,一个dthen填充'列表',不要使用'object.toString()',迭代'List '并且获得'themedate'的值并且填充'列表' – 2015-01-21 08:28:54

回答

0

结果请与此尝试。

<c:forEach var="themedays" items="${map.themeday}"> 
    <c:foreach var="theme" items="${themedays}"> 
     <b> ${theme} </b> 
    </c:foreach> 
</c:foreach> 
+0

对不起,我得到结果 “主题演讲”。其实我需要得到结果 01/14/2015 DAY1007 02/14/2015 DAY1008 – 2015-01-21 06:40:19

+0

@PriyankaShaju现在就试试,回答编辑 – 2015-01-21 06:41:55

+0

得到值[Ljava.lang.Object; @ a3e5fc [Ljava.lang.Object; @ 502bb9。不是确切的值。 – 2015-01-21 06:51:35

0

下面的方法可以应用于与字符串遍历HashMap和bean的对象列表

<c:forEach items="${map}" var="events"> 
// iterate the key here 
    StringValues= ${events.key} 
// iterate the values of list here 
    <c:forEach items="${events.value}" var="item" > 
     ${item} 
    </c:forEach> 
</c:forEach> 

在这里看到:

+0

它还印刷价值 列表值这里[Ljava。lang.Object; @ 1a99a72 [Ljava.lang.Object; @ 1dada3。其实我需要得到结果01/14/2015 DAY100 02/14/2015 DAY107 – 2015-01-21 06:49:19

+0

@Priyanka似乎你没有正确访问bean的属性,你能用你正在尝试的代码更新你的问题吗? – 2015-01-21 07:02:07

+0

只是还是熬不过使用List 结果=而不是List 结果=(名单)query.list(名单)query.list()()。你能解释一下如何在列表中存储我的DaoImpl中的值。 – 2015-01-21 08:15:08

相关问题