2012-07-16 16 views
0

我有一個通知消息列表,我從數據庫中提取並放入會話中的一個servlet中。然後使用requesDipstacher.forward(request,response轉發到一個jsp頁面)。我現在採取的消息和循環播放的列表,通過使用JSTL:如何在會話中使用列表並在Javascript中使用它

<c:foreach value = "item" items = '${sessionScope.notification}'> 
    <a href = "javascript:printAll('${item}'}>Print</a> 
</c:foreach> 

的JavaScript看起來像這樣

function printAll(item) 
{ 
    display(item) //note this is pseudo code . Here I kind of display the items. 
} 

現在我的問題是,有太多太多的鏈接在我的網頁顯示print。我想將整個列表發送到JavaScript並遍歷它並顯示單個消息。這可能與JavaScript.Kindly指出我相同的問題,如果它存在。

+0

什麼是項目?什麼包含? – 2012-07-16 17:01:49

+0

item只是列表中contsins在那個迭代值 – 2012-07-16 17:13:09

+0

你的意思,你不想多次顯示打印?那麼當你想顯示該通知消息?請讓我們知道你想要什麼,更清晰的方式? – 2012-07-16 17:09:37

回答

0

如果沒有問題,把的JavaScript在頁面的同一個文件,你可以把這樣的事情:

<script> 
function printAll() 
{ 
    var html = '<ul>'; 
    <c:foreach value = "item" items = '${sessionScope.notification}'> 
    html += '<li>${item}</li>'; 
    </c:foreach> 
    html += '</ul>'; 
    display(html); 
} 
</script> 

<a href = "javascript:printAll();">Print</a> 

當你注意到它,也有不同的方法來解決問題。