how to display data from controller to jsp using s

2019-09-06 17:23发布

问题:

Hi I am unable to display data from controller to jsp page in spring, am new to spring, this is my controller

List<DocDto>  list =DocService.getDocs();
            DocDto docList = new DocDto();
            docList.setdocType(doc_type);
            docList.setdocSubType(doc_subtype);
            jobList.setTransactionId(transaction_id);   
            model.addAttribute("docList", docList);

This is my jsp table

 <c:forEach var="o" items="${list}">
 <tr> 
<td>
<c:out value="${o.doc_type}" /></td>
<td><c:out value="${o.doc_subtype}" /></td>
</td>
</tr>

This is not displaying any data in my jsp, just simply blank table it is displaying. Any help would be appreciated.

回答1:

Instead of ${list} use ${docList} in for each loop. If it did not works then follow following steps :

Check you included proper jstl library in jsp

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

and using proper jar for jstl library.

Check DocDto for doc_type,doc_subtype variables properly spelled or not.



回答2:

You're calling your model attribute docList, but you're trying to reference it as list. Try

<c:forEach var="o" items="${docList}">

instead



回答3:

In your case you have bind model.addAttribute("docList", docList); and you are trying to iterate by list you can use this model.addAttribute("list ", docList); then iterate .Hope it will work