使用分页显示表格中元素的元素

发布于 2024-12-06 08:24:29 字数 265 浏览 1 评论 0原文

我是 JSP 新手,所以请耐心等待。

我正在尝试创建一个 JSP 页面,该页面将显示我已获取的一些对象的表。这些对象中包含一个数组。在表中,我希望有一个超链接,甚至是一个按钮,它将用户发送到一个页面,该页面将显示对象内包含的数组。

我目前有一个 for 循环遍历容器对象列表(保存数组),并且该循环构造主表,我让它显示容器对象的其他元素。

我应该使用什么技术将容器对象表链接到另一个具有数组表的页面? (位于容器对象中)来自容器对象的每个链接都需要链接到其包含的数组。

I'm new to JSP, so bear with me.

I'm trying to make a JSP page that will display a table of some objects that I have fetched. Contained inside these objects is an array. In the table, I want there to be a hyperlink, or even a button, that will send the user to a page that will display the array contained inside the object.

I currently have a for-loop going through the list of container objects (which hold the array), and that loop constructs the main table, I have it displaying other elements of the container object.

What technique should I use to have the table of container objects link to another page which has a table of the array? (which is in the container object) Each link from a container object needs to link to its contained array.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扶醉桌前 2024-12-13 08:24:29

您的问题缺少有关这些容器及其来源的一些基本信息。如果它们来自数据库,那么建议的路线是放置到另一个页面的链接,传递容器对象的 PK。这样,第二个页面将重新获取容器并显示其数组。

如果您的容器无法再次获取,我建议使用 javascript/jquery magic 在同一页面中显示数组。这将导致更大的 HTML 内容,但将避免将内容存储在某种基于用户的缓存中。

Your question is missing some basic information about the these containers and their origin. If they are coming from a database then the suggested route is to put in a link to another page passing the PK of the container object. This way, the second page will refetch the container and display its array.

if your container cannot be fetched a second time, I suggest then using javascript/jquery magic to display the array in the same page. This will result in larger HTML content but will avoid having to store the content in some sort of user's based cache.

挖个坑埋了你 2024-12-13 08:24:29

好吧,让我用一个订单示例来解释一下。订单是一个集合,您希望在主页中列出整个集合。单击链接时,您希望显示与特定订单项目相关的详细信息。

在这种情况下,您可以使用 c:forEach 迭代集合。

 
<c:forEach var="orderDetail" items="orders">
<a href="/myProj/orderDetail?orderId=${orderDetail.id}">Order Detail</a>
</c:forEach>

每个列表都会有一个带有参数的链接,该参数唯一标识上述项目。
请注意,orderDetail 是一个 servlet(或任何控制器)。请求发送到 servlet,它读取请求参数。通过 orderId 参数,它获取关联的订单对象,将其放置在请求范围内的名称下,例如 orderDetailModel 并将请求分派到 orderDetailsPage.jsp orderDetailsPage.jsp 仅找到此 orderDetailModel code> 来自请求范围的对象并显示它。

就像 ${orderDetailModel.placedTime}

希望这个例子有帮助。

Well, let me explain with a Order example. Orders is a collection and you want to list the entire collection in the mainpage. When a link is clicked you want to show the details pertaining to the particular order item.

In this case, you'd iterate through the collection using c:forEach

 
<c:forEach var="orderDetail" items="orders">
<a href="/myProj/orderDetail?orderId=${orderDetail.id}">Order Detail</a>
</c:forEach>

Each listing would have a link with a parameter that uniquely identifies the item as above.
Note here that the orderDetail is a servlet (or any controller). The request goes to the servlet, it reads the request parameter. With the orderId parameter it takes the associated order object, places it in request scope under a name, say orderDetailModel and dispatches the request to orderDetailsPage.jsp The orderDetailsPage.jsp merely finds this orderDetailModel object from request scope and displays it.

Like ${orderDetailModel.placedTime}

Hope this example helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文