我正在尝试使用 JSTL 在现有的 JSP 代码中创建分页,但我不确定我在示例之一中看到的以下语法。
<sql:setDataSource var="dataSrc"
url="jdbc:oracle:thin:@127.0.0.1:1521:database_name"
driver="oracle.jdbc.driver.OracleDriver"
user="user_name" password="pass_word"/>
然后运行查询:
<sql:query var="queryResults" dataSource="${dataSrc}">
select system_id, employeename from employees
</sql:query>
然后,在网页上显示结果:
<table>
<tr>
<th>ID</th>....
我的问题是 这是我必须使用的标准语法还是我该输入什么在这个 query var= ?
以及 dataSource ="{dataSrc}"
中,这是标准代码还是我必须修改它?
如果有人可以指导我如何在每页上显示限制为 10 的表格或行的源示例,我将非常感激。
I'm trying to use JSTL to create a pagination in my existing JSP code but I am not sure about the following syntax which I've seen in one of the examples.
<sql:setDataSource var="dataSrc"
url="jdbc:oracle:thin:@127.0.0.1:1521:database_name"
driver="oracle.jdbc.driver.OracleDriver"
user="user_name" password="pass_word"/>
Then you run a query:
<sql:query var="queryResults" dataSource="${dataSrc}">
select system_id, employeename from employees
</sql:query>
Then, you display the results on the web page:
<table>
<tr>
<th>ID</th>....
My question is <sql: query var="queryResults"
is this a standard syntax I must use or what do I put inside this query var= ?
and also the dataSource ="{dataSrc}"
is this a standard code or must I modify this?
If someone can direct me to a source example of how to display my tables or rows limited to 10 on each page I'd be very grateful.
发布评论
评论(2)
我以前写过自己的分页标签 - 我真希望我没有写过。
我建议您查看 displaytag。它是一个易于使用的开源标签库,几乎可以满足您所有的分页要求。它生成的 HTML 是干净的并且符合标准,最重要的是,它已经被编写了 :-)
对于正确的分页,用法可以像这样简单:
${paginationList} 是结果集的第 1 到 10 项(您将需要在 DAO 中编写代码以从数据库中分块检索项目,大多数 ORM 库都可以让您轻松完成此操作,或者您也可以使用 SQL 来完成此操作 - 请参阅下面的示例)。
${totalNumberOfItems} 是如果您没有将结果数量限制为页面大小 10,则查询将返回的项目总数。同样,大多数 ORM 框架允许您相当轻松地执行此操作,或者您也可以这样做使用 SQL(例如 select count(*)...) - 见下文...
有关 Hibernate 中分页的示例,请查看 这个。有关 JDBC 示例,请查看此。
I've written my own pagination tag before - I really wish I hadn't.
I would suggest you take a look at displaytag. It's an easy to use open source tag library that should pretty much cover all your pagination requirements. The HTML it produces is clean and standards compliant and best of all, it's already been written :-)
For proper pagination, usage can be as simple as this:
${paginatedList} is e.g. items 1 to 10 of your resultset (you'll need to write the code in your DAO to retrieve items from your database in chunks. Most ORM libraries allow you to do this pretty easily, or you can do it with SQL - see below for examples).
${totalNumberOfItems} is the total number of items your query would return if you didn't limit the number of results to a page size of 10. Again, most ORM frameworks allow you to do this fairly easily, or again you can do it with SQL (e.g. select count(*)...) - see below...
For an example of pagination in Hibernate, take a look at this. For a JDBC example, have a look at this.
有了一点额外的知识,您就可以使用
下面的参考指南中的 Struts 2.0 分页 JSP 代码 spinet,
请参阅 此处获取完整参考。我认为这正是您所需要的。
With a little bit of extra knowledge you could have used Struts 2.0 pagination
JSP code spinet from below reference guide
see here for the complete reference. I think this is what you exactly need.