日期:2014-05-19 浏览次数:20695 次
<body>
<%
request.setCharacterEncoding("UTF-8");//设置编码
String strPageNum = request.getParameter("pageNum");//获得当前页数
int pageNum = 1;
//把当前页数的字符串转换为数字,如果失败则为1,即首页
try{
pageNum = Integer.parseInt(strPageNum);
}catch(Exception e){
pageNum = 1;
}
ShowAllSongs showAllsongs = new ShowAllSongs();//实例化
showAllsongs.setCountRow();//设置总行数
showAllsongs.setCountPage();//设置总页数
int countPage = showAllsongs.getCountPage();//获得总页数
//如果当前页数小于 0 或者大于总页数,则把当前页重新设置为1
if(pageNum<=0 || pageNum>countPage){
pageNum = 1;
}
showAllsongs.setCurrentlyPage(pageNum);//设置当前页
int currentlyPage = showAllsongs.getCurrentlyPage();//获得当前页
List<Songs> songList = showAllsongs.getSongsPaginQuery(pageNum);
//分页查询
if(songList!=null){
%>
<table border="1" align="center">
<tr>
<th align="center">歌曲名称</th>
<th align="center">歌曲编号</th>
<th align="center">分类编号</th>
<th align="center">歌手</th>
<th align="center">加入时间</th>
<th align="center">频道</th>
<th align="center">点击率</th>
</tr>
<%
for(int i = 0;i<songList.size();i++){
Songs songs = songList.get(i);
%>
<tr>
<td width="200"><%=songs.getTitle() %></td>
<td width="200"><%=songs.getSongid() %></td>
<td width="200"><%=songs.getTypeid() %></td>
<td width="200"><%=songs.getSinger() %></td>
<td width="200"><%=songs.getDateandtime() %></td>
<td width="200"><%=songs.getChannel() %></td>
<td width="200"><%=songs.getHits() %></td>
</tr>
<%
}
%>
<tr>
<td colspan="7" align="center">
<%
if(currentlyPage==1){
%>
共<%=countPage %>页
当前第<%=currentlyPage %>页
<a href="showSongList.jsp?pageNum=1">首页</a>
<a href="showSongList.jsp?pageNum=<%=currentlyPage-1 %>">上一页</a>
下一页
尾页
<%
}else{
%>
共<%=countPage %>页
当前第<%=currentlyPage %>页
<a href="showSongList.jsp?pageNum=1">首页</a>
<a href="showSongList.jsp?pageNum=<%=currentlyPage-1 %>">上一页</a>
<a href="showSongList.jsp?pageNum=<%=currentlyPage+1 %>">下一页</a> &