Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

about Database page turning question!  RSS feed

 
tom richard
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody!

I'am a JSP beginner. can you help me to reslove this problem.. thanks!


here is the source code:

<%@page contentType="text/html;charset=gb2312"%>
<%@page import="java.sql.*,user.*"%>
<jsp:useBean id="mydata" class="user.AccessData" scope="page" />
<%
if(mydata.openData("e:\\site\\sm.mdb"))
{

ResultSet rs=mydata.queryRecord("select count(*) from open");
rs.next();
int total=rs.getRow();
rs.close();
rs=mydata.queryRecord("select * from open");
int currentpage=1;
int pagesize=10;
int restrictPage=pagesize;
int pages=0;
if(total%pagesize>0)
{
pages=total/pagesize+1;
}
else
{
pages=total/pagesize;
}
if(request.getParameter("page")!=null)
{
currentpage=Integer.parseInt(request.getParameter("page"));
if(currentpage<0)
{
currentpage=0;
}
if(currentpage>pages)
{
currentpage=pages;
}
rs.absolute((currentpage-1)*pagesize+1);
}


%>

<style type="text/css">
<!--
td {
font-family: "Arial";
font-size: 12px;
line-height: 16px;
color: #000000;
text-decoration: none;
}
-->
</style>
</head>

<body>
<table width="600" border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#999999">
<tr bgcolor="#FF0000">
<th scope="col">ID</th>
<th scope="col">SCHOOL</th>
<th scope="col">COURSE</th>
<th scope="col">TIME</th>
<th scope="col">RULE</th>
<th scope="col">STATUS</th>
</tr>
<%
while(rs.next()&& restrictPage>0)
{
String course=rs.getString(1);
String school=rs.getString(2);
String studydate=rs.getString("date");
String rule=rs.getString("rule");
int id=rs.getInt("id");
restrictPage--;

%>
<tr bgcolor="#FFFFFF" align="center">
<td><%=id%></td>
<td><%=school%></td>
<td><%=course%></td>
<td><%=studydate%></td>
<td><%=rule%></td>
<td><a href="del.jsp?id=<%=id%>">DELETE</a> MODIFY</td>
</tr>

<%
}
rs.close();
}
else
{
out.print("Database proessed error!!!");
}


%>
<tr align="center" bgcolor="#efefef">
<td colspan="6">[<a href="2.jsp?page=<%=currentpage-1%>">Previous</a>] [<a href="2.jsp?page=<%=currentpage+1%>">Next</a>] [<a href="2.jsp?page=1">First</a>] [<a href="2.jsp?currentpage=<%=pages%>">Last</a>] 共<%=pages%>Page/Current<%=currentpage%>Page Total:<%=total%>Records </td>
</tr>
</table>
</body>
</html>



runtime error:




org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 97 in the jsp file: /2.jsp
Generated servlet error:
C:\tomcat\work\Catalina\localhost\_\org\apache\jsp\_2_jsp.java:165: cannot resolve symbol
symbol : variable currentpage
location: class org.apache.jsp._2_jsp
out.print(currentpage-1);
^


An error occurred at line: 97 in the jsp file: /2.jsp
Generated servlet error:
C:\tomcat\work\Catalina\localhost\_\org\apache\jsp\_2_jsp.java:167: cannot resolve symbol
symbol : variable currentpage
location: class org.apache.jsp._2_jsp
out.print(currentpage+1);
^


An error occurred at line: 97 in the jsp file: /2.jsp
Generated servlet error:
C:\tomcat\work\Catalina\localhost\_\org\apache\jsp\_2_jsp.java:169: cannot resolve symbol
symbol : variable pages
location: class org.apache.jsp._2_jsp
out.print(pages);
^


An error occurred at line: 97 in the jsp file: /2.jsp
Generated servlet error:
C:\tomcat\work\Catalina\localhost\_\org\apache\jsp\_2_jsp.java:171: cannot resolve symbol
symbol : variable pages
location: class org.apache.jsp._2_jsp
out.print(pages);
^


An error occurred at line: 97 in the jsp file: /2.jsp
Generated servlet error:
C:\tomcat\work\Catalina\localhost\_\org\apache\jsp\_2_jsp.java:173: cannot resolve symbol
symbol : variable currentpage
location: class org.apache.jsp._2_jsp
out.print(currentpage);
^


An error occurred at line: 97 in the jsp file: /2.jsp
Generated servlet error:
C:\tomcat\work\Catalina\localhost\_\org\apache\jsp\_2_jsp.java:177: cannot resolve symbol
symbol : variable total
location: class org.apache.jsp._2_jsp
out.print(total);
^
6 errors



why ? .... ??

int currentpage=1;
int pagesize=10;
int restrictPage=pagesize;
int pages=0;

Variables already definition..
[ May 03, 2005: Message edited by: Bear Bibeault ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom,

If you post large amounts of code (more than 1 or 2 lines) wrapping it within UBB Code tags will preserve your indenting.

I suspect the problem is due to the currentpage variable being declared inside an "if" block and maybe being called outside of that if block.
This would be quickly discernable with proper indenting.

Take a look at your code and see if all the out.println(currentpage... statements have access to that variable.
[ May 03, 2005: Message edited by: Ben Souther ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66141
141
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
tom, welcome to the ranch.

Here's a few pointers to help get you off on the right foot:

Firstly, when posting code, please use the UBB code tags to preserve the formatting of your code. Few people are going to look at pages and pages of unformatted and unindented code in order to help you. The CODE button below the text area where you enter your reply will automatically insert such tags for you -- place your code examples between them.

Secondly, you are discovering one of the many many reasons why placing Java processing code in a JSP page is a bad idea. Aside from being architecturally incorrect, it makes things very difficult to debug. My suggestion is to refactor your code such that Java processing is performed in Java classes rather than on-page. You could do this with Javabeans, or better yet, investigate the architectural pattern of n-tiered web applications (also look up the terms MVC and 'Model 2').
 
tom richard
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Firstly, The problem is resolved , I know where the question is. it is my first time come to the ranch. I hope you will help me more in the future. thanks a lot.

Secondly, thank you (Ben&Bear) for your suggestion. I will use UBB code tags next time.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad it's working.
Thank you for posting back.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!