Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在JSP表中拆分数组值_Java_Arrays_Jsp - Fatal编程技术网

Java 在JSP表中拆分数组值

Java 在JSP表中拆分数组值,java,arrays,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.ge

如何为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 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>

描述
名称
价格

有人能帮我做这个编码吗。我如何调用每个项目

试着像这样使用每个jstl的
foreach

添加这些
taglib

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

和用于显示数据的代码

   <c:forEach begin="0" end="${fn:length(result) - 1}" var="idx">
    <tr>
      <th>Description</th><td><c:out value="${result[idx]}"/></td>
      <th>Name</th><td><c:out value="${result[idx]}"/></td>
      <th>Price</th><td><c:out value="${result[idx]}"/></td>
   </tr>
 </c:forEach>

描述
名称
价格

您可以这样做:

<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>

描述
名称
价格

在打印语句中打印html您写道您想要分割值,您是在谈论在
数组上循环以显示一行中的每个项吗?@jhamon是的,我是在谈论循环以及如何在选项卡中显示谢谢。它可以工作,但我可以问你,我应该把${yourListAsBean}放在哪里