Reputation: 381
How to get LinkedHashMap in the jsp page which is added in ModelAndView object in the spring controller.Please see the below code:
UserDTO:
public class UserDTO{
public byte[] data;
public String user;
public Long id;
public byte[] getData() {
return data;
}
public void setData(byte[] data) {
this.data = data;
}
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
Controller:
@RequestMapping(value = "/showData", method = RequestMethod.GET)
public String showRequest(final HttpServletRequest request,
HttpServletResponse response, ModelMap model,
@RequestParam("ID") String Id) {
MyDTO myRequestDTO = new MyDTO();
String viewName = "myData";
final ModelAndView mav = new ModelAndView();
LinkedHashMap<Long,UserDTO> myList = myRequestsDTO.getAllRecords();
/* UserDTO userDoc = null;
Long userDocKey;
if(!myList.isEmpty()){
for (Map.Entry<Long,UserDTO> doc : myList.entrySet()) {
userDoc = doc.getValue();
userDocKey = doc.getKey();
System.out.println("User = " + userDoc.getUser() + " User Name = " + userDoc.getData());
} } */
mav.addObject("myList", myList);//want to get this myList in jsp page and get the details from that.
return viewName;
}
Please suggest how to get the LinkedHashMap stored in ModelAndView object and get "userDoc.getUser() ", "userDoc.getId()" and "userDoc.getData()" from that map as i have shown in above controller code. I know that this can be achieved using JSTL but as i'm new to it please let me know the solution which is much helpful to me.
Upvotes: 0
Views: 1596
Reputation: 9336
You can iterate over your map with JSTL using foreach
.
<c:forEach var="entry" items="${myList}">
Key : <c:out value="${entry.key}"/>
User : <c:out value="${entry.value.user}"/>
Id : <c:out value="${entry.value.id}"/>
Data : <c:out value="${entry.value.data}"/>
</c:forEach>
Upvotes: 2