java - JSP 表中的拆分数组值

标签 java arrays jsp

如何拆分 JSP 的数组值,我正在尝试拆分数组值并放入表中

 <%
        String query = request.getParameter("item");
    ItemSearch is = new ItemSearch();   
    ArrayList<Items> result = is.doSearch(query);
    for(Items item : result)
    {   
        out.println(item.getImg());
        out.println(item.getHref());
        out.println(item.getTitle());
        out.println(item.getPrice());
        out.println(item.getDesc());
        //out.println(item.toString());

    }

    %>

这是我的 table 。

<table border="1">
                <thead>
                    <tr>
                        <th>Description</th>
                        <th>Name</th>
                        <th>Price</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td><%= out.println(item.getDesc)%></td>
                        <td></td>
                        <td></td>
                    </tr>

任何人都可以帮我完成这个编码吗?我如何调用每个项目

最佳答案

你可以这样做:

<table border="1">
<thead>
    <tr>
        <th>Description</th>
        <th>Name</th>
        <th>Price</th>
    </tr>
</thead>
<tbody>
<%
String query = request.getParameter("item");
ItemSearch is = new ItemSearch();   
ArrayList<Items> result = is.doSearch(query);
for(Items item : result)
{   
    %>
    <tr>
    <td><%= item.getDesc) %></td>
    <td><%= item.getTitle() %></td>
    <td><%= item.getPrice() %></td>
   </tr>
   <%
}
%>
</table>

但是

使用 Scriplets 是恐龙技术。你不应该再使用它。而是使用 EL 例如

<table border="1">
    <thead>
        <tr>
            <th>Description</th>
            <th>Name</th>
            <th>Price</th>
        </tr>
    </thead>
    <tbody>
<c:forEach var="item" items="${yourListAsBean}">
<tr>
  <td><c:out value="${item.desc}" /></td>
  <td><c:out value="${item.title}" /></td>
  <td><c:out value="${item.price}" /></td>
</tr>
</c:forEach>
</table>

关于java - JSP 表中的拆分数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34292157/

相关文章:

java - JSOUP 在 HTML 文件中找到所有具有 ALT 属性的图像?

c# - 如何使用 HttpContext 获取 int 值而不是 string 值?

java - spring boot hibernate 5 集成报错

arrays - E1012 常量表达式违反子范围界限;为什么它适用于变量?

Java:是否可以在for循环内换行x次?

java - fx.prp.file.name 转 字符串

java - ListView 项目未显示在主 Activity 上

ios - 在 iOS 中解析 json 并将值添加到对象数组

eclipse - java.lang.ClassNotFoundException : com. ebank.rajeev.controller.Login 登录

javascript - 在jsp中运行javascript函数