⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 show.jsp

📁 课程设计中的在线书店源码
💻 JSP
字号:
<%@ page contentType="text/html;charset=gb2312" import="java.sql.*"%>
<%@ include file="top.htm"%>
<jsp:useBean id="conn" class="dbBean.DBBean" scope="session"/>
<jsp:useBean id="sp" class="spage.ShowPage"/>
<html>
<head>
<title>分类查看</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<%!
	String type="times";
	String sql1="";
	String sql2="";
	ResultSet rs=null;
	ResultSet temp=null;
	//每页显示的记录个数
	int size = 10;
	//当前页号
	int p = 1;
	//全部的页数
	int totalPage = 1;
%>
<%
	if(request.getParameter("stype")!=null)
		type=request.getParameter("stype");
%>
<p>
<center>
<form action="show.jsp" method="post">
按&nbsp;&nbsp;<select name="stype">
		<option value="times" <%if(type!=null) if(type.equals("times")) out.print("selected");%>>下载次数</option>
		<option value="star" <%if(type!=null) if(type.equals("star")) out.print("selected");%>>推荐指数</option>
		<option value="addtime" <%if(type!=null) if(type.equals("addtime")) out.print("selected");%>>加入时间</option>
		<option value="name" <%if(type!=null) if(type.equals("name")) out.print("selected");%>>软件名称</option>
	      </select>&nbsp;&nbsp;顺序查看
&nbsp;&nbsp;<input type="submit" value="确定">
</form>
<table width="95%">
<tr align="center">
<th background="images/bg1.gif">类型</th><th background="images/bg1.gif">名称</th><th background="images/bg1.gif">推荐指数</th><th background="images/bg1.gif">下载次数</th><th background="images/bg1.gif">加入时间</th>
<%
	sql1="select * from sinfo order by "+type+" desc";
	sql2="select count(*) from sinfo";
	temp=conn.executeQuery(sql2);
	int totalrecord=0;
	if(temp.next())
		totalrecord = temp.getInt(1);
	// 如果是当前页码的整数倍	
	if(totalrecord % size ==0) totalPage = totalrecord / size;  
	// 如果最后还空余一页
	else  totalPage = totalrecord / size + 1; 
	if(totalPage == 0) totalPage = 1;
	temp.close();
	try {
		if(request.getParameter("p")==null|| request.getParameter("p").equals("")) 
		{
		   if(session.getAttribute("showp")==null)
			p = 1;
		   else
			p = ((Integer)session.getAttribute("showp")).intValue();
		}
		else
		{
		   p = Integer.parseInt(request.getParameter("p"));			   session.setAttribute("showp",new Integer(p));
		}
	} 
	// 捕获用户从浏览器地址拦直接输入非数字信息而引起的异常
	catch(NumberFormatException e) {  
		   p = 1;
	}
	if(p < 1)  p = 1;
	if(p > totalPage) p = totalPage;
	rs=conn.executeQuery(sql1);
	if(rs.next())
		out.println(sp.printPage(rs,p,size,false));
%>
</table>
<form Action="show.jsp" Method="GET">
<%
  for(int i=1;i<=totalPage;i++) {
      out.println("<a href=show.jsp?p=" + i +">" + i + "</a>&nbsp;&nbsp;");
  }
%>
  <p>输入页数:<input type="text" name="p" size="3"> 
     页数:<font color="red"><%=p%>/<%=totalPage%></font> 
  </p>
</form>
</center>
<%
	rs.close();
	conn.close();
%>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -