jsp分页报错问题..
大家好..
请大家帮忙看看..
tomcat报错如下:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 36 in the jsp file: /booklist2.jsp
Generated servlet error:
Syntax error on tokens, delete these tokens
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
____________________________________________________________________
它好象说booklist2.jsp的36行出错..
但是36行是 " <% "的代码片段的开头..
这个分页代码是我从网上搜索回来的..
之前booklist2.jsp显示数据是没有问题的..
下面贴出我booklist2.jsp的代码:
<%@ page contentType= "text/html;charset=gb2312 " %>
<%@ include file= "incoming/common.jsp "%>
<html>
<head>
<title> 网络书店 </title>
<%
DBSQLManager dbsm = new DBSQLManager();
String sql= "SELECT * FROM bookinfo order by DATET DESC ";
dbsm.setSqlStr(sql);
dbsm.executeQuery();
ResultSet rs=dbsm.getRs();
int i;
%>
<%
String pg=request.getParameter( "pg ");
if(pg==null)
pg= "1 ";
int tt;//记录总数
rs.last();
//得到纪录条数
tt=rs.getRow();
//指回接过级首位
rs.first();
int pagex;
//这里的 tt%10 为每页显示纪录的条数,可以自己定义
if(tt%10==0)
//这里计算共多少页,有于数,那么页数+1
{pagex=(tt/10);}
else
{pagex=(tt/10)+1;}//计算总页数
int pagey;//从用户那里得到的目标页
pagey=Integer.parseInt(pg);
如果页数小于1,那么把页数设置成1
if(pagey <1)
{
pagey=1;
}
//如果页数大于总页数,那么设置成最大页数
if(pagey> pagex)
{
pagey=pagex;
}
//翻页开始,调整记录指针的位置
int n=(pagey-1)*10+1;
int a;
for(a=0;a <n-1;a++)
{
if(!rs.isLast())
rs.next();
}
//翻页结束
%>
<table width= "700 " border= "1 " cellpadding= "0 " cellspacing= "0 " bordercolor= "#FFFFFF ">
<tr>
<td width= "39% " height= "20 " bgcolor= "#3399FF "> <div align= "center " class= "STYLE2 ">
<div align= "left "> 书名 </div>
</div> </td>
<td width= "14% " bgcolor= "#3399FF "> <div align= "center " class= "STYLE2 ">
<div align= "left "> 作者 </div>
</div> </td>
</tr>
<!-- 循环输出开始 -->
<% for(i=0;i <10;i++)
{ if(!rs.isAfterLast()){ %>
<tr>
<td height= "21 " bgcolor= "#D5F0F4 "> <a href= "xianxi.jsp?isbn= <%=rs.getString( "ISBN ")%> "> <div align= "left "> <%=rs.getString( "TITLE ")%> </div> </a> </td>
<td bgcolor= "#D5F0F4 "> <div align= "left "> <%=rs.getString( "AUTHOR ")%> </div> </td>
</tr>
<% rs.next();
}
} %>
</table>
<form name= "form1 " method= "post " action= "booklist2.jsp ">
<div align= "center "> <a href= "booklist2.jsp?pg=1 "> 首页 </a> |
<%
if ((pagey-1)> =1){
%>
<a href= "booklist2.jsp?pg= <%=(pagey-1)%> "> 上一页 </a>
<%}
else{out.print( "上一页 ");}
%>
|
<%
if ((pagey+1) <=pagex){
%>
<a href= "booklist2.jsp?pg= <%=(pagey+1)%> "> 下一页 </a>
<%}
else{out.print( "下一页 ");}
%>
| <a href= "booklist2.jsp?pg= <%=pagex%> "> 尾页 </a> 每页10条 共 <%=pagex%> 页
<!-- 下拉菜单开始 -->
<select name= "pg " id= "pg ">
<%
int pg1=0;
for(pg1=1;pg1 <=pagex;pg1++){
%>
<option value= " <%=pg1%> " <%
if(pagey==pg1)
{out.print( "selected ");}
%> > <%=pg1%> </option>
<%}%>
</select>
<!-- 下拉菜单结束 -->
页
<input type= "submit " name= "Submit " value= "go ">
</div>
</form>
<%
rs.close();
%>
<p> </p>
<%@ include file= "incoming/footer.jsp "%>
</body>
</html>
麻烦大家看看..
谢谢..
[解决办法]
int i;这个是不是应该写在声明里啊?
<%!
int i=0;
%>
[解决办法]
String pg=request.getParameter( "pg ");
改成
String pg = String.valueOf(request.getParameter( "pg "));
如果还报什么错请把错误信息贴出来
[解决办法]
兄弟 能问下你的 没有异常处理 编译不出错吗 我在这个问题已经困扰很长时间了
不知道怎么解决啊 大虾能告诉我吗
我的异常网推荐解决方案:org.apache.jasper.JasperException: Unable to compile class,http://www.myexception.cn/j2ee/2308.html