java - 如何在jsp中显示表格中的值?

标签 java javascript jsp jstl

我是 jsp 和 jSTL 的新手,我正在编写此代码,以使用 for 循环从数组中获取值。我正在获取输出,但我想将该输出放入表中。如何做到这一点任何人都可以帮忙我?

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

最佳答案

客户端,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>

不要忘记声明 jSTL 标签库,并将 jSTL 库添加到类路径

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

从服务器端,您需要将列表返回到您的jsp,如下所示:

req.setAttribute("themeList", somelist);

但考虑使用一些MVC框架

关于java - 如何在jsp中显示表格中的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13759149/

相关文章:

java - <s :form> to decide in the action class 中的两个按钮

java - JSP中显示JSON数据时出现异常

java - 如何使用 REST Web 服务器维护登录状态?

java - 在不重新提示的情况下从其他类接收数组到方法中时出现问题

java - 在 jtextarea 中显示带有换行符和间距的文本

javascript - 日期对象上的代理

javascript - 在 Ember 中,this 和 this.controller 有什么区别

javascript - CSS 相当于 .attr ("data-html", "true")

java.lang.NoClassDefFoundError : org/skife/jdbi/v2/DBI 错误

java - 两个 war 文件之间的通信,无需对上下文根进行硬编码