查询后的数据点击下一页传送不过去查询的字符串

a274375013 2016-09-30 01:00:05
JSP代码:
<%@ page language="java" import="java.util.*,gao.java.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
String user=(String)session.getAttribute("user");
if(user==null){
response.sendRedirect("Login.jsp?flag=login");
}
ArrayList<Student> al=(ArrayList<Student>)request.getAttribute("Student");
ArrayList<String> Tea_name=(ArrayList<String>)request.getAttribute("Tea_name");
String name=(String)request.getAttribute("name");
String tea_name=(String)request.getAttribute("teacher");
String Name=request.getParameter("name");
String teaname=request.getParameter("teacher");


%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>学生信息</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->

</head>
<script type="text/javascript">
function check(){
return window.confirm("是否确定删除学生");
}
</script>

<body>
<table width="900" border="2" align="center" cellpadding="0" cellspacing="0" height="800">
<tr height="260">
<td ><jsp:include page="M_Top.jsp"></jsp:include></td>
</tr>
<tr height="440"><td><form action="ManagerServlet?flag=student" method="post">
<table width="900" border="2" align="center">
<tr>
<td align="left" height="30" valign="top" ><h4>当前页面:<a href="Manager.jsp">管理员</a>→学生管理</h4></td>
</tr>

<tr>
<td align="center" height="70"><h2>学生信息</h2></td>
</tr>

<tr >
<td align="center" height="30">学生任课教师:
<label>
<select name="Tea_name" id="select">
<%
if(tea_name!=null&&tea_name.equals("")==false){
%>
<option selected="selected"><%=tea_name %></option>
<%
}
%>
<option></option>
<%
for(int i=0;i<Tea_name.size();i++){
%>
<option><%=Tea_name.get(i) %></option>
<%
}
%>
</select>
       学生姓名:
<%
if(name!=null){
%>
<input name="name" type="text" id="name" value="<%=name %>" size="15" />
<%
}else{
%>
<input name="name" type="text" id="name" value="" size="15" />
<%
}
%>
  
<input type="submit" name="query" id="query" value="查询" />
</label></td>
</tr>
<tr>
<td height="280"><table width="80%" border="2" align="center">
<tr>
<td align="center" height="30">ID</td>
<td align="center">学号</td>
<td align="center">姓名</td>
<td align="center">密码</td>
<td align="center">任课教师</td>
<td align="center"><a href="Manager_stu_psdAlter.jsp">修改密码</a></td>
<td align="center"></td>
</tr>
<%

if(al==null||al.size()==0){

%>
<tr>
<td align="center" colspan="7">没有相关记录</td>
</tr>
<%
}else{
for(int i=0;i<al.size();i++){
Student st=al.get(i);%>
<tr>
<td align="center" height="25"><%=st.getStu_ID() %></td>
<td align="center" height="25"><%=st.getStu_num() %></td>
<td align="center"><%=st.getStu_name() %></td>
<td align="center"><%=st.getStu_psd() %></td>
<td align="center"><%=st.getStu_class() %></td>
<td align="center"><a href="Manager_StudentServlet?flag=alter&Stu_ID=<%=st.getStu_ID() %>">修改信息</a></td>
<td align="center"><a href="Manager_StudentServlet?flag=delete&Stu_ID=<%=st.getStu_ID() %>" onClick="javascript:return check()">删除学生</a></td>
</tr>
<%
}
}
%>
</table></td>
</tr>
<tr>
<%
int pageCount=Integer.parseInt((String)request.getAttribute("pageCount"));
int pageNow=Integer.parseInt((String)request.getAttribute("pageNow"));
%>
<td align="center" height="30">共有 <font color="#FF0000"><%=request.getAttribute("rowCount") %></font> 条
    共有 <font color="#FF0000"><%=pageCount%></font> 页
    当前 <font color="#FF0000"><%=pageNow %></font> 页
    <a href="ManagerServlet?flag=student&pageNow=1&name=<%=Name %>&Tea_name<%=teaname %>">首页</a>
<% if(pageNow!=1){

%>
    <a href="ManagerServlet?flag=student&pageNow=<%=pageNow-1 %>&name=<%=Name %>&Tea_name=<%=teaname %>">上一页</a>
<%
}
%>
<% if(pageNow!=pageCount){

%>

    <a href="ManagerServlet?flag=student&pageNow=<%=pageNow+1 %>&name=<%=Name %>&Tea_name=<%=teaname %>">下一页</a>
<%
}
%>
    <a href="ManagerServlet?flag=student&pageNow=<%=pageCount %>&name=<%=Name %>&Tea_name=<%= teaname %>">尾页</a>
    
<label>
<select name="pageNow" id="select">
<option></option>
<%
for(int i=1;i<=pageCount;i++){

%>
<option><%=i %></option>
<%
}
%>
</select>
    
<input type="submit" name="button" id="button" value="前往" />
</label></td>
</tr>
</table></form>
</td>
</tr>
<tr height="100">
<td align="center"><jsp:include page="Tail.jsp"></jsp:include><br></td>
</tr>
</table>
</body>
</html>


SEVLET相关的代码
if(flag.equals("student")){
String tea_name=request.getParameter("Tea_name");
int tea_ID=dbh.getID("select Tea_ID from Tea_tb where Tea_name='"+tea_name+"'");
//得到按班级查询的班级名并据此查询其ID号
String name=request.getParameter("name");//得到模糊查询中输入的名字
ArrayList<Student> al=new ArrayList<Student>();
if((tea_name!=null||name!=null)&&(tea_name.equals("")==false||name.equals("")==false)){//用于判断是不是第一次显示,即通过管理主页面的学生管理链接而来
if((tea_name!=""||name!="")&&(tea_name.equals("")==false||name.equals("")==false)){//用于判断是不是需要按条件进行查询
if(tea_name==""||tea_name.equals("")==true){//按名字进行模糊查询
al=dbh.getStudent("select top "+pageSize+" * from Stu_tb where Stu_name like '%"+name+"%' and Stu_ID not in (select top "+pageSize*(pageNow-1)+" Stu_ID from Stu_tb where Stu_name like '%"+name+"%')");
rowCount=dbh.getRowCount("select count(*) from Stu_tb where Stu_name like '%"+name+"%'");
request.setAttribute("name", name);
request.setAttribute("teacher", "");
}else if(name==""||name.equals("")==true){//按班级进行查询
al=dbh.getStudent("select top "+pageSize+" * from Stu_tb where Stu_class= '"+tea_ID+"' and Stu_ID not in (select top "+pageSize*(pageNow-1)+" Stu_ID from Stu_tb where Stu_class='"+tea_ID+"')");
rowCount=dbh.getRowCount("select count(*) from Stu_tb where Stu_class='"+tea_ID+"'");
request.setAttribute("name", "");
request.setAttribute("teacher", tea_name);
}else{//按班级和名字同时进行查询
al=dbh.getStudent("select top "+pageSize+" * from Stu_tb where Stu_class='"+tea_ID+"' and Stu_name like '%"+name+"%' and Stu_ID not in (select top "+pageSize*(pageNow-1)+" Stu_ID from Stu_tb where Stu_class='"+tea_ID+"' and Stu_name like '%"+name+"%')");
rowCount=dbh.getRowCount("select count(*) from Stu_tb where Stu_class='"+tea_ID+"' and Stu_name like '%"+name+"%'");
request.setAttribute("name", name);
request.setAttribute("teacher", tea_name);
}
}else{//无条件查询,显示所有学生信息
al=dbh.getStudent("select top "+pageSize+" * from Stu_tb where Stu_ID not in (select top "+pageSize*(pageNow-1)+" Stu_ID from Stu_tb)");
rowCount=dbh.getRowCount("select count(*) from Stu_tb");
}
request.setAttribute("name", "");
request.setAttribute("teacher", "");
} else{//第一次显示所有学生信息。
al=dbh.getStudent("select top "+pageSize+" * from Stu_tb where Stu_ID not in (select top "+pageSize*(pageNow-1)+" Stu_ID from Stu_tb)");
rowCount=dbh.getRowCount("select count(*) from Stu_tb");
request.setAttribute("name", "");
request.setAttribute("teacher", "");
}

if(rowCount%pageSize==0) pageCount=rowCount/pageSize;
else pageCount=rowCount/pageSize+1;
//通过rowCount和pageSize的关系来计算pageCount的值
ArrayList<String> laoshi=dbh.getAttribute("select Tea_name from Tea_tb");
//得到所有的教师的名称,并将他们放入一个集合中
request.setAttribute("Student", al);
request.setAttribute("pageNow", pageNowStr);
request.setAttribute("pageCount",pageCount+"");
request.setAttribute("rowCount", rowCount+"");
request.setAttribute("Tea_name", laoshi);
request.getRequestDispatcher("Manager_Student.jsp").forward(request,response );


查询后的分页应该是根据查询的内容分页,可点击下一页后好像一开始查询输入的字符串传不过来,下一页总出现错误。
...全文
267 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

23,406

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧