i want to write common page for viewing data list or single object.
In controller:
ArrayList<Table> tables;
request.setAttribute("tables", tables);
and JSP:
<table >
<c:forEach var="table" items="${tables}">
<tr>
<th><c:out value=" ${table.name}" /></th>
</tr>
</c:forEach>
</table>
Shows good.
When i pass single object –
Table table;
request.setAttribute("table", table);
does not show anything;
Than i try pass
Table tables;
request.setAttribute("tables", tables);
i have error
Don't know how to iterate over supplied "items" in <forEach>
This is a pretty simple example, my application must view a lot of data of this object, and make two similar pages with the same code it silly.
How to solve this problem? add this single object to the list or there is another solution?
It seems like you want to pass single element instead of list. One way to solve this is to build a list with single element and pass it. Use following to create list with only one element in it.