📄 temp.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page language="java" import="java.sql.*"%>
<%@page import="java.io.*"%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String db=getServletContext().getRealPath("\\")+"music.mdb";
File dbpath=new File(db);
String path = new java.io.File(db).getAbsolutePath();
Connection conn= DriverManager.getConnection("jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};" +
"DBQ="+path);
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
try{%>
<Table Border="0" align="center" class="table">
<TR class='1'>
<TH width=100>图片</th>
<TH width=100>歌曲</th>
<TH width=100>歌手</th>
<TH width=100>播放</th>
</TR>
<%
ResultSet rs=stmt.executeQuery("select id,pic,music,name,type from mp3 where type=1");
rs.next();
int intPageSize; //一页显示的记录数
int intRowCount; //记录总数
int intPageCount; //总页数
int intPage; //待显示页码
String strPage;
int i;
//设置一页显示的记录数
intPageSize=2;
//MySelf=Request.ServerVariables("PATH_INFO");
//取得待显示页码
strPage=request.getParameter("page");
if(strPage==null)//表明在QueryString中没有Page这一个参数,此时显示第一页数据
{intPage=1;}
else{//将字符串转换成整型
intPage=java.lang.Integer.parseInt(strPage);
if(intPage<1) {intPage=1;}
}
//获取记录总数
rs.last();
intRowCount=rs.getRow();
//记算总页数
intPageCount =(intRowCount+intPageSize-1)/intPageSize;
//调整待显示的页码
if(intPage>intPageCount)
{ intPage=intPageCount;}
if(intPageCount>0)
{
//将记录指针定位到待显示页的第一条记录上
rs.absolute((intPage-1)*intPageSize+1);
//显示数据
i=0;
while(i<intPageSize &&! rs.isAfterLast()){
%>
<tr class="3">
<%
String img=rs.getString(2);
if(img==null)
{
img="bg.jpg";
}
%>
<td align="center"><%if(img=="bg.jpg"){%><img src="img/<%=img%>" height="71" width="91"><%}else{%><a href="img/<%=img%>" target="_blank"><img src="img/<%=img%>" height="71" width="91"></a><%}%></td>
<td align="center"><%=rs.getString(3)%></td>
<td align="center"><%=rs.getString(4)%></td>
<td align="center"><% int type=rs.getInt("type");
if(type==1){
%><a href="mp3.jsp?id=<%=rs.getInt(1)%>&page=<%=intPage%>"><img src="play.gif" height="20" width="20"></a>
<%
}else if(type==2)
{
%><a href="video.jsp?id=<%=rs.getInt(1)%>"><img src="video.gif" height="20" width="20"></a><%}%>
</td>
</tr>
<%
rs.next();
i++;
}}
%>
</table>
<center>
总共有<font color="#0000FF" size="5"><%=intRowCount%></font>条记录|分为<font color="#0000FF" size="5"><%=intPageCount%></font>页|现在是第<font color="#0000FF" size="5"><%=intPage%></font>页<br>
<%if(intPage<2){ %> 首页 | 上一页
<% }else{%> <a href="mp3.jsp?page=1&id=<%=id%>">第一页</a>|<a href="mp3.jsp?page=<%=intPage-1%>&id=<%=id%>">上一页</a>
<%}%>
<%if((intPageCount-intPage)<1){ %>下一页 | 尾页
<%}else{%>
<a href="mp3.jsp?page=<%=intPage+1%>&id=<%=id%>">下一页</a> | <a href="mp3.jsp?page=<%=intPageCount%>&id=<%=id%>">最后一页</a>
</center>
<%}
rs.close();
}
catch(Exception e){
out.println(e.getMessage());
}
stmt.close();
conn.close();
%>
</table>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -