如何拆分 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/