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

📄 brow.jsp

📁 这是一个关于jsp的学习文档.为学习jsp的朋友提供方便
💻 JSP
字号:
<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" import="java.sql.*" %>
<%@ page import="java.lang.Math.*" %>
<jsp:useBean id="conn" scope="page" class="download.conn"/>
<jsp:useBean id="rstogbk" scope="page" class="download.RsToGbk"/>
<%!
	ResultSet rs = null;
	ResultSet rsTmp = null;
	String m_type = "";
	String m_key = "";
	String sql = "";
	String sqltmp = "";
	int PageSize = 10;
	int Page = 1;
	int totalPage = 1;
%>
<%
request.setCharacterEncoding("GBK");
m_type = request.getParameter("m_type");
if(m_type==null || m_type.equals("")) {
	m_type = "showname";
}
m_key = request.getParameter("m_key");
if(m_key==null) {
	m_key = "";
}
sql = "Select * From download ";
sqltmp = "select count(id) as countid from download ";
if(m_key.equals("")){
sql = sql;
sqltmp = sqltmp;
}else{
sql =  sql1 + "Where " + m_type + " like '%" + m_key + "%'";
sqltmp += " where " + m_type + " like '%" + m_key + "%'";
}	
%>
<html>
<head>
	<title>我的软件仓库</title>
	<Link rel="stylesheet" type="text/css" href="style.css">
</head>
<body TEXT="#000000" BGCOLOR="#FFFFFF" BACKGROUND="b01.jpg">
<Center>
<%@include file="title.htm"%>
<h2>我的软件仓库-分类查询</h2>
<form action="brow.jsp" method="get">
	请选择类别:
	<Select name="m_type">
		<option value="showname" <%if(m_type.equals("showname")) out.print("selected");%>>软件名称</option>
		<option value="softnote" <%if(m_type.equals("typename")) out.print("selected");%>>软件类别</option>
	</Select>
	请输入关键字:
	<Input type="text" name="m_key">
	<Input type="Submit" Value="查看">
</form></Center>
<%
int totalrecord=0;
try {
	rsTmp = conn.executeQuery( sqltmp );
	if(rsTmp==null || !rsTmp.next()) {
		out.println("未找到任何数据!");
		return;
	}
	totalrecord = rsTmp.getInt("countid");
}catch(Exception ee) {
    out.println("访问数据库出错!<br>");
	out.println(ee.toString());
	return;
}
rsTmp.close();
if(totalrecord % PageSize ==0) totalPage = totalrecord / PageSize;  // 如果是当前页码的整数倍
else  totalPage = (int) Math.floor( totalrecord / PageSize ) + 1;   // 如果最后还空余一页
if(totalPage == 0) totalPage = 1;
PageSize = 10;
if(request.getParameter("Page")==null || request.getParameter("Page").equals(""))
   Page = 1;
else {
   try {
	   Page = Integer.parseInt(request.getParameter("Page"));
   }catch(NumberFormatException e) {
	   Page = 1;
   }
}
if(Page < 1)  Page = 1;
if(Page > totalPage) Page = totalPage;
rs = conn.executeQuery( sql );

try {
	// 下面调用在RsToGbk中的ShowOnePage方法
	// ShowOnePage( ResultSet, 页数, 每页记录数)
	out.println( rstogbk.ShowOnePage(rs, Page, PageSize) );
} catch(Exception e)  {
    out.println("没有符合条件的记录!");
}
rs.close();
%>
<form Action="brow.jsp" Method="GET" name=form1>
<Center>
<% 
   if(Page != 1) {
      out.println("<A HREF=brow.jsp?Page=1&m_key=" + m_key  + "&m_type=" + m_type   + ">第一页</A>

⌨️ 快捷键说明

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