Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

pagination with jsp

 
J Das
Ranch Hand
Posts: 83
Firefox Browser Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am unable to do pagination in jsp. please help me ..
i have a database named mytable where i have a table named student(rollNo , name , marks , grade)
i connect to the database using the following code named connect.java which is in a package named common :






when i run it on netbeans i get the following error report on my browser :

HTTP Status 500 -

type Exception report

message

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

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /pagination.jsp at line 47

44: connect c = new connect();
45: con = c.getConnection();
46: String query1 = "SELECT SQL_CALC_FOUND_ROWS * FROM student limit " + iPageNo + "," + showRows + "";
47: ps1 = con.prepareStatement(query1);
48: rs1 = ps1.executeQuery();
49:
50: String query2 = "SELECT FOUND_ROWS() as cnt";


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

root cause

java.lang.NullPointerException
org.apache.jsp.pagination_jsp._jspService(pagination_jsp.java:102)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.26 logs.
Apache Tomcat/6.0.26
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like your Connection con is null at line 45.

Why do you not have a null check on it prior to preparing the statement.

Also, there is way too much Java scriptlets in this JSP.

WP

 
J Das
Ranch Hand
Posts: 83
Firefox Browser Java MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan wrote:Looks like your Connection con is null at line 45.

Why do you not have a null check on it prior to preparing the statement.

Also, there is way too much Java scriptlets in this JSP.

WP



Thank you for your reply WP. I admit the code has too much sciplets in it which is not fair.. but through the net i have found nothing that suits my necessity in generating pagination.. So please help me with some code.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64972
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the JspFaq on this subject?
 
Manish Sridharan
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest to refactor your code and move Pagination logic in java class and call this class in some pagination.jsp and include that pagination.jsp wherever you need pagination. it will make your jsp more cohesive.


Thanks,

 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
William P O'Sullivan wrote:Looks like your Connection con is null at line 45.

is that con is null or c is null?
<edit>thats why probably william ask you to not put java code in jsp?(just guessing :) )</edit>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic