使用JSP在下一页中显示表信息 [英] Display the table info in the next page using JSP

查看:135
本文介绍了使用JSP在下一页中显示表信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用JSP编写此Web应用程序,这是我的大学项目. 单击书本"按钮时,它将重定向到新页面,在该页面中将再次显示表格信息.表中可能有多行,每行都有一个书本按钮.我的问题是如何检索单击书本按钮并在下一页中显示的行.谢谢你 在用户单击书本按钮的表的屏幕快照

I am writing this web app in JSP as my college project. When clicking the book button it redirected to a new page where the table information will be shown again. There could be multiple rows in the table each row having a book button. My question is how to retrive the row where the book button is clicked and show in next page. thank you Sreecnshot of the table where user will click the book button

推荐答案

您需要完成两件事:

  1. 将按钮包装在表单中.
  2. 为每个表单注入"条目/行标识符.

因此,通常您的jsp代码如下所示:

So, usually your jsp code looks like this:

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

从示例中您可以看到,每次迭代都可以访问theme.id(在这种情况下为行标识符).

You can see from the sample that on each iteration you have access to theme.id which is row identifier in the case.

您需要对代码进行类似操作(查找每行的标识符是什么).然后,您需要将所有按钮包装成表格:

You need to do similar with your code(find what is an identifier for every row). Then you need to wrap all buttons into forms:

    <td>
        <form action="/secondPage">
            <input type="hidden" value="${theme.id}">
            <input type="submit" value="Book">
        </form>
    </td>

然后,在页面上只需从请求参数中检索值并在数据库中找到数据->显示它即可.

Then on your page just retrieve the value from request parameters and find the data on your database -> display it.

这篇关于使用JSP在下一页中显示表信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆