[求助]继续求助,关于分页的诚心求教!

06-03-03 IKARI_DALI
这次出现报错了:

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /index.jsp(36,0) Unterminated <%@ include tag

org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)

org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)

org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:134)

org.apache.jasper.compiler.Parser.parseDirective(Parser.java:511)

org.apache.jasper.compiler.Parser.parseElements(Parser.java:1539)

org.apache.jasper.compiler.Parser.parse(Parser.java:126)

org.apache.jasper.compiler.ParserController.doParse(ParserController.java:220)

org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)

org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:490)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:471)

org.apache.jasper.compiler.Compiler.compile(Compiler.java:459)

org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

servlet.TopServlet.doGet(TopServlet.java:32)

javax.servlet.http.HttpServlet.service(HttpServlet.java:689)

javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:34)

说是标签没有结束,但是我怎么找也没发现错误,还是把代码贴出来,大家帮我看看吧~谢谢啦!^_^

index.jsp

<%@page contentType="text/html;charset=gbk" language="java" import="java.sql.*,bean.*,servlet.*"%>

<%@include file="manager\getuser.jsp"%>

<jsp:useBean id="pageCtl" class="bean.PageBean" scope="request"/>

<html><body>

<p>

<%

try

{

out.print("欢迎你"+ub.getUsername());%>

<a href="addcon.jsp"> 点击发表新贴</a>

<a href="logout.jsp">注销</a></p><%

}

catch(Exception e)

{

%>

你还没有登录,请先<a href="alogin.jsp">登录</a>,

如果没有注册,请<a href="reg.jsp">注册</a><%

}

%>

<table border=1>

<%java.util.Vector v=pageCtl.getResult();

java.util.Enumeration e=v.elements();

while(e.hasMoreElements())

{

Object[] obj=(Object[])e.nextElement();%>

<tr>

<td><%=obj[0]%></td>

<td><%=obj[1]%></td>

<td><%=obj[2]%></td>

</tr><%}%>

</table>

<%

if(pageCtl.maxPage!=1)%>

<form name="Pag***" action="/topservlet" method="post">

<%@include file="page.jsp">

</form>

<%}%>

</body></html>

还有其中嵌套的page.jsp(getuser.jsp应该没错,因为在别的页面上都通过了)

<script language="JavaScript">

<!--

function Jumping(){

document.Pag***.submit();

return ;

}

function gotoPage(pageN){

document.Pag***.jumpPage.value = pageN;

document.Pag***.submit();

return ;

}

-->

</script>

每页<%=pageCtl.rowsPerPage%>行

共<%=pageCtl.maxCout%>行

第<%=pageCtl.curPage%>页

共<%=pageCtl.maxPage%>页

<%if(pageCtl.curPage==1){ out.print(" 首页 上一页"); }else{ %>

<A HREF="javascript:gotoPage(1)">首页</A>

<A HREF="javascript:gotoPage(<%=pageCtl.curPage-1%>)">上一页</A>

<%}

if(pageCtl.curPage==pageCtl.maxPage){ out.print("下一页 尾页"); }else{ %>

<A HREF="javascript:gotoPage(<%=pageCtl.curPage+1%>)">下一页</A>

<A HREF="javascript:gotoPage(<%=pageCtl.maxPage%>)">尾页</A>

<%}%>

转到第<SELECT name="jumpPage" onchange="Jumping()">

<% for(int i=1;i<=pageCtl.maxPage;i++) {

if (i== pageCtl.curPage){

%>

<OPTION selected value=<%=i%>><%=i%></OPTION>

<%}else{%>

<OPTION value=<%=i%>><%=i%></OPTION>

<%}}%>

</SELECT>页

PageBean.java

package bean;

import bean.*;

import java.util.Vector;

public class PageBean

{

public int curPage;//当前第几页

public int maxPage;//一共几页

public int maxCout;//一共几行

public int pageCout=10;//每行几页

public java.util.Vector data;

public PageBean()

{

}

public void Cmaxpage()

{

if(this.maxCout%this.pageCout==0)

{

this.maxPage=this.maxCout/this.pageCout;

}

else

{

this.maxPage=this.maxCout/this.pageCout+1;

}

}

public Vector getResult()

{

return this.data;

}

public PageBean(PBusinessBean pageC)throws Exception

{

this.maxCout=pageC.getAvailableCount();

this.data=pageC.getResult();

this.Cmaxpage();

}

}

PBusinessBean.java

package bean;

import java.sql.*;

import bean.*;

import java.util.*;

public class PBusinessBean

{

private Connection conn=null;

private ResultSet res=null;

private java.sql.PreparedStatement prepar=null;

private java.sql.CallableStatement proc=null;

Vector v;

public PBusinessBean()throws Exception//connection

{

String CLASSFORNAME="com.mysql.jdbc.Driver";

String URL="jdbc:mysql://localhost:3306/ikaribbs?useUnicode=true&characterEncoding=GBK";

String USER="ikaridali";

String PW="TRSTTT";

Class.forName (CLASSFORNAME);

conn=java.sql.DriverManager.getConnection(URL,USER,PW);

v=new Vector();

}

public int getAvailableCount()//select the max count in table

{

int ret=0;

String sql="select count(*) from topic";

try

{

PreparedStatement prepar=conn.prepareStatement(sql);

ResultSet res=prepar.executeQuery();

while(res.next());

{

ret = res.getInt(1);

}

}

catch(Exception e)

{

e.printStackTrace();

}

return ret;

}

public PageBean listData(String page)throws Exception//for topic

{

try

{

PageBean pageBean=new PageBean(this);

int pageN=Integer.parseInt(page);

String sql="select top"+pageN*pageBean.pageCout+"* from topic order by crTime";

PreparedStatement prepar=conn.prepareStatement(sql);

res=prepar.executeQuery();

int i=0;

while(res.next())

{

if(i>(pageN-1)*pageBean.pageCout-1)

{

Object[] obj=new Object[6];

obj[0]=res.getString("title");

obj[1]=res.getString("creater");

obj[2]=res.getString("article");

//obj[3]=res.getString("crTime");

//obj[4]=new Integer(res.getInt("re"));

//obj[5]=new Integer(res.getInt("cli"));

//obj[6]=res.getString("lstAnswer");

//obj[7]=res.getDate("lstRet");

v.add(obj);

}

i++;

}

res.close();

prepar.close();

pageBean.curPage=pageN;

pageBean.data=v;

return pageBean;

}

catch(Exception e)

{

e.printStackTrace();

throw e;

}

}

public Vector getResult()throws Exception

{

return v;

}

}

TopServlet.java

package servlet;

import javax.servlet.*;

import javax.servlet.http.*;

import java.io.*;

import java.util.*;

import bean.*;

public class TopServlet extends HttpServlet

{

private static final String CONTENT_TYPE="text/html;charset=GBK";

public void init() throws ServletException

{}

public void doGet(HttpServletRequest requ,HttpServletResponse resp) throws ServletException,IOException

{

resp.setContentType("text/html; charset=GBK");

requ.setCharacterEncoding("GBK");

resp.setCharacterEncoding("GBK");

//PrintWriter out=response.getWriter();

try

{

PBusinessBean pageC=new PBusinessBean();

PageBean pageCtl=pageC.listData((String)requ.getParameter("jumpPage"));

requ.setAttribute("pageCtl",pageCtl);

}

catch(Exception e)

{

e.printStackTrace();

}

javax.servlet.RequestDispatcher dis=requ.getRequestDispatcher("/index.jsp");

dis.forward(requ,resp);

}

public void doPost(HttpServletRequest requ, HttpServletResponse resp)

throws ServletException, IOException

{

doGet(requ,resp);

}

public void destroy()

{

}

}

很不好意思又是这么大一驼......我的论坛就剩下这个了,说实话分页在逻辑上我也不是很清楚,最好有谁能帮我解释一下(总感觉"第几页"这个值获得的有点像先有鸡还是先有蛋一样奇怪......),不过最主要的是能帮我解答这个错误,这对我来说实在是太重要啦!大哥大姐一定要帮我~实在谢谢~~

banq
2006-03-09 10:34
原理可见Jdon框架开发批量查询原理,具体这里就不罗嗦了

你的错误:

>org.apache.jasper.JasperException: /index.jsp(36,0) Unterminated

很好解决,表示你的index.jsp第36行书写错误,可能一个标签没有结束符号

/>

猜你喜欢