*
The moose likes JSP and the fly likes pagination with jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "pagination with jsp" Watch "pagination with jsp" New topic
Author

pagination with jsp

J Das
Ranch Hand

Joined: Jul 27, 2011
Posts: 83

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

Joined: Mar 28, 2012
Posts: 859

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

Joined: Jul 27, 2011
Posts: 83

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

Joined: Jan 10, 2002
Posts: 61105
    
  66

Have you read the JspFaq on this subject?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Manish Sridharan
Ranch Hand

Joined: Jul 19, 2005
Posts: 64
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,


Manish S.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pagination with jsp