How to pass a List from the controller to jsp?

jsp, spring

Solution

I have done such thing using jstl in jsp. Take a look in my code. Here my list is "inf" and my objects have different fields, but I think you will manage to adapt it:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<!DOCTYPE >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Real time info</title>
<link href="webjars/bootstrap/3.3.6/css/bootstrap.min.css"
                    rel="stylesheet">
</head>
    <body>
    <div class="container">
        <table class="table table-striped">
            <caption><h3>Result (People):</h3></caption>
            <thead>
                <tr class="tr tr-success">
                    <td>Id</td>
                    <td>Name</td>
                    <td>PIN</td>
                </tr>   
            </thead>
            <tbody>
                <c:forEach items="${inf}" var="temp">
                    <tr>
                        <td>${temp.id}</td>
                        <td>${temp.name}</td>
                        <td>${temp.pin}</td>
                        <td>
                            <a class="btn btn-info" href="/update-person?id=${temp.id}">Update</a>
                            <a class="btn btn-danger" onclick="return confirm('Are you sure you want to delete?')" href="/delete-person?id=${temp.id}">Delete</a>
                        </td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
    </div>
    <script src="webjars/jquery/2.2.4/jquery.min.js"></script>
    <script src="webjars/bootstrap/3.3.6/js/bootstrap.min.js"></script>
</body>
</html>

And here is that specific part of the controller:

@RequestMapping(value = "/search", method = RequestMethod.POST)
    public String handleRequest(@RequestParam String search,
            ModelMap model){
        List<UserInfo> inf = searchServ.listPeople(search);
        model.put("inf", inf);
        return "info";
    }

Your thing is very similar. I hope that will help you. Just to add - I am using bootstrap to style my graphical user interface.

Problem

I am implementing a bulletin board with spring framework. To show the list of articles on jsp, I got some info from DB and saved it to `List<BulletinBoardList>`. What I want to do is to take this List to jsp and save it. I tried with the code below: ``` @RequestMapping(value = "/", method = RequestMethod.GET) public String home(Locale locale, Model model) { logger.info("Welcome home! The client locale is {}.", locale); /* Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate ); */ List<BulletinBoardList> result = sqlSession.selectList("board.getList"); model.addAttribute("list", result); return "home"; } ``` Next, this code is for retrieving the List from controller: ``` <%@ page import com.heesu.third.BulletinBoardList, java.util.List %> <% BulletinBoardList list = ${list} %> ``` But it never works.

Original source