<%@ page contentType="text/html;charset=gb2312" %>
<%@ include file="../inc/incdb.jsp"%>
<%@ include file="session.jsp"%>
<%int classid =(null==request.getParameter("classid")?1:(Integer.parseInt(request.getParameter("classid"))));%>
<%int page1 = (null==request.getParameter("page")?1:(Integer.parseInt(request.getParameter("page"))));%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
<meta http-equiv="refresh" content="60*30">
<title>欢迎光临<%=title%></title>
<link rel="stylesheet" href="../css/css.css" type="text/css" media="screen">
</head>
<body>
<BR><BR>
<TABLE bgColor=<%=tablebgcolor%> border=0 cellPadding=0 cellSpacing=1 width=70% align=CENTER>
<TR><TD align=middle background=../img/index/topback.gif height=10>
</TD></TR>
</TABLE>
<TABLE align=center border=0 cellPadding=6 cellSpacing=1 width=70% bgColor=<%=tablebgcolor%>>
<TBODY>
<TR>
<TD bgColor=<%=tdbgcolor2%> colspan=3 align=center><FONT SIZE="3" COLOR="#ffffff"><B>后台管理</B></FONT></TD>
</TR>
<TR>
<TD bgColor=<%=tdbgcolor2%> colspan=3><A HREF="addnews.jsp">添加新闻</A>
&nbsp;&nbsp;<A HREF="mastermanage.jsp">管理员管理</A>(系统管理员专用)
&nbsp;&nbsp;<A HREF="classmanage.jsp">栏目管理</A>(系统管理员专用)
&nbsp;&nbsp;<A HREF="logout.jsp">退出</A>
&nbsp;&nbsp;<A HREF="javascript:this.location.reload()">刷新</A>
&nbsp;&nbsp;<A HREF="../home.jsp">主页</A></TD>
</TR>
<TR>
<TD bgColor=<%=tdbgcolor2%> colspan=2 width=70%>
<form name="myform">
<select name="select" size="1" onchange="location=this.options[this.selectedIndex].value">
<option value="main.jsp">请选择新闻所的栏目</option>
<% Vector listclass = new Vector();
DispClass dispclass = new DispClass();
listclass = dispclass.allClass();
for(int i=0;i<listclass.size();i++) {
IClass classinfo = (IClass)listclass.elementAt(i);
if (classid==classinfo.getID()){%>
<option value="main.jsp?classid=<%=classinfo.getID()%>" selected><%=classinfo.getName()%></option><%} else{%>
<option value="main.jsp?classid=<%=classinfo.getID()%>"><%=classinfo.getName()%></option>
<%}}%>
</select>
</form>
</TD>
<TD align=center bgColor=<%=tdbgcolor2%> width=30%>
<%DispNews dispnews = new DispNews();
dispnews.setRootID(classid);
int newscount = dispnews.newsNum();%>&nbsp;&nbsp;共有<FONT COLOR="red"><%=newscount%></FONT>条新闻
</TD>
</TR>
<%
int perPage = 10;
int intPageCount = 0;intPageCount = (newscount + perPage-1) / perPage;
if(page1 < 1) page1 = 1;
if(page1 > intPageCount) page1 = intPageCount;
int startPage=((page1-1)/10)*10+1;%>
<% Vector listnews = new Vector();
dispnews.setRootID(classid);
listnews = dispnews.rootidToNews();
for(int j=0;j<listnews.size();j++) {
News newsinfo = (News)listnews.elementAt(j);
if(j<(page1-1)*perPage || j>page1*perPage-1){continue;}%>
<TR>
<TD bgColor=<%=tdbgcolor4%> width=8%><%=j+1%></TD>
<TD bgColor=<%=tdbgcolor4%> width=70%><A HREF="editnews.jsp?id=<%=newsinfo.getID()%>"><%=newsinfo.getTopic()%></A></TD>
<TD bgColor=<%=tdbgcolor4%> width=22% align=center><A HREF="editnews.jsp?id=<%=newsinfo.getID()%>">编辑新闻</A>
&nbsp;<A HREF="delnews.jsp?id=<%=newsinfo.getID()%>">删除新闻</A></TD>
</TR>
<%}%>
</TBODY>
</TABLE><TABLE border=0 cellPadding=0 cellSpacing=0 width="70%" align=center>
<TR>
<TD align=middle vAlign=baseline>
<FORM action="main.jsp?page=<%=page1%>&classid=<%=classid%>" method=GET>
<p align='left'>
<%System.out.println("page1:"+page1);%>
直接跳到第<INPUT name=page size=1>页<INPUT TYPE="submit">&nbsp;每页显示<font color=red><%=perPage%></font>条新闻&nbsp;共<font color=red><%=newscount%></font>条新闻&nbsp;第<font color=red><%=startPage%></font>页&nbsp;
共<font color=red><%=intPageCount%></font>页 </FONT></p></TD>
</FORM>
<TD align=middle vAlign=baseline></TD>
<TD align=right width='50%'><p align='right'>分页:
<%=pageShow(startPage,page1,intPageCount,classid)%>
</p></TD>
</TR>
</TABLE><TABLE border=0 cellPadding=0 cellSpacing=0 width="70%" align=center>
<TR bgColor=<%=trbgcolor2%>>
<TD align=middle background=../img/index/botback.gif vAlign=bottom width="100%">
<TABLE border=0 cellPadding=0 cellSpacing=0 width="100%" align=center>
<TR>
<TD width=1><IMG border=0 height=17 hspace=0 src="../img/index/left.gif" width=14></TD>
    <TD align=middle width="100%"></TD>
    <TD align=right width=1><IMG border=0 height=17 hspace=0 src="../img/index/right.gif"  width=14></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<%@ include file="../inc/tail.jsp"%><%!
//快速跳转
 String pageShow(int startPage,int intPage,int intPageCount,int classname1){
StringBuffer buf = new StringBuffer();
if (startPage>10)
buf.append("<a class=list href='main.jsp?page="+(startPage-1)+"&classid="+classname1+"' title='前十页'><FONT face=webdings>9</FONT></a>&nbsp");
else
buf.append("<FONT face=webdings color='#ff0000'>9</FONT></a>&nbsp"); if(intPage>1) 
buf.append("<a class=list href='main.jsp?page="+(intPage-1)+"&classid=" + classname1+"' title='上一页'><FONT face=webdings>7</FONT></a>&nbsp;");
else
buf.append("<FONT face=webdings color='#ff0000'>7</FONT></a>&nbsp;"); int i=0;
buf.append("[&nbsp;");
for(i=startPage;i<=startPage+9;i++){
if(i==intPage){
buf.append("<font color='#ff0000'>"+i+"</font>");
buf.append("&nbsp;");
}else{
buf.append("<a class=list href=main.jsp?page=" +i+ "&classid="+classname1+" title='第"+i+"页'>"+ i +"</a>&nbsp;");
}
if(i==intPageCount) {
i++;
break;
}
}
buf.append("]&nbsp;");
    if(intPage!=intPageCount) 
buf.append("<a class=list href='main.jsp?page="+(intPage+1)+"&classid=" + classname1+ "' title='下一页'><FONT face=webdings>8</FONT></a>&nbsp;");
else
buf.append("<FONT face=webdings color='#ff0000'>8</FONT></a>&nbsp;");
if(i<=intPageCount) 
buf.append("<a class=list href='main.jsp?page="+i+"&classid=" + classname1+ "' title='后十页'><FONT face=webdings >:</FONT></a>");
else
buf.append("<FONT face=webdings color='#ff0000'>:</FONT></a>");
return buf.toString();
}
%>--------------------------问题分割线---------------------------------------我的问题很简单,就是下面的代码:<FORM action="main.jsp?page=<%=page1%>&classid=<%=classid%>" method=GET>
<p align='left'>
<%System.out.println("page1:"+page1);%>
直接跳到第<INPUT name=page size=1>页<INPUT TYPE="submit">&nbsp;每页显示<font color=red><%=perPage%></font>条新闻&nbsp;共<font color=red><%=newscount%></font>条新闻&nbsp;第<font color=red><%=startPage%></font>页&nbsp;
共<font color=red><%=intPageCount%></font>页 </FONT></p></TD>
</FORM>这段代码是实现页面跳转功能的,比如在输入框输入3的时候
页面就跳转到3,但就这地方出现问题了
当我输入3的时候,IE地址栏显示的是:http://localhost:8080/news/admin/main.jsp?page=3
                           而不是:http://localhost:8080/news/admin/main.jsp?page=3&classid=25
也就是classid的值没有提交上(<FORM action="main.jsp?page=<%=page1%>&classid=<%=classid%>" method=GET>)但在前面明明有这句:<%int classid =(null==request.getParameter("classid")?1:(Integer.parseInt(request.getParameter("classid"))));%>
这句应该是获取classid的值吧,但不明白为什么没有提交上。

解决方案 »

  1.   

    分页分的好乱,把那个分页组件写到一个javaBean里面,
    import java.util.List;public class Pager {
    protected int pageSize=25;
    protected int pageNo=1;
    protected int rowCount=0;
    protected int pageCount=1;
    protected int startIndex=1;
    protected int endIndex=0;protected int firstPageNo=1;
    protected int prePageNo=1;
    protected int nextPageNO=1;
    protected int lastPageNo=1;protected List resultList;
    public Pager(int pageSize,int pageNo,int rowCount,List resutList){
    if(rowCount%pageSize==0){
    this.pageCount=rowCount/pageSize;
    }else{
    this.pageCount=rowCount/pageSize+1;
    }
      this.startIndex=pageSize*(pageNo-1);
      this.endIndex=this.startIndex+resultList.size();
      
      this.lastPageNo=this.pageCount;
      
      if(this.pageNo>1) this.prePageNo=this.pageNo-1;
      
      if(this.pageNo==this.lastPageNo){
      this.nextPageNO=this.lastPageNo;
      
      }
      else{
      this.nextPageNO=this.pageNo+1;
      }
    }
    }
      

  2.   

    因为点下一页的时候没有运行submit  form 你哪个参数没有提交上去,一个办法是加个session进去,然后用session取这个参数
      

  3.   

    不好意思各位,原来是BUG问题