如何在jsp中显示表中的值?

Mit*_*kar 2 javascript java jsp jstl

我是jsp和jstl的新手我正在研究这个代码,使用for循环从数组中获取值.我正在获取输出,但是我想把这个输出放到table.how中这样做可以帮助我吗?

for ( int i =0; i < timeSize ; i++)
       {
         out.println(resource[i]);
         out.println(itimespend[i]);
         out.println(icostspend[i]);
         totalcost += itimespend[i] * icostspend[i];          
        }
Run Code Online (Sandbox Code Playgroud)

小智 20

客户端,jsp

<table>
    <tr>
        <th>ID</th>
        <th>Theme</th>
    </tr>
    <c:forEach items="${themeList}" var="theme" varStatus="status">
        <tr>
            <td>${theme.id}</td>
            <td>${theme.theme}</td>
        </tr>
    </c:forEach>
</table>
Run Code Online (Sandbox Code Playgroud)

不要忘记声明jstl taglib,并将jstl libs添加到classpath

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
Run Code Online (Sandbox Code Playgroud)

从服务器端你需要将一个列表返回给你的jsp,如下所示:

req.setAttribute("themeList", somelist);
Run Code Online (Sandbox Code Playgroud)

但考虑使用一些MVC框架