Hi all,
I was trying to implement pagination in JSP and I came accross a sample code. I tried it on my PC and it worked..
so there were two basic classes at the back of this system and I modified them to suit my need and tried to compile them.. one of them compiled with no hassle but the other will not.
I have all files in the same folder
(
1. pagingData.java
2. Controller.java
3. DataAccess: This class I use for database connection and have no trouble with it)
*** pagingData is instantiated inside Controller.
inside the Controller there is a list and I am trying to add instance of pagingData into it.
*** when I comment out the code for the adding into list the code compiles ok.
Please someone help me with this.
A Million Thanks in advance.
Codes are added below
pagingData.java
import java.util.*;
import java.sql.*;
import DB.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.io.Serializable;
public class pagingData implements Serializable {
public pagingData( ) {
// initFileList( );
}
private int No;
private int job_Id;
private String Employer;
private String job_Title;
private String job_Description;
private String closing_Date;
public pagingData(int No, int job_Id, String Employer,String job_Title,String job_Description,String closing_Date) {
this.No = No;
this.job_Id = job_Id;
this.Employer = Employer;
this.job_Title = job_Title;
this.job_Description = job_Description;
this.closing_Date=closing_Date;
}
public int getNo() {
return No;
}
public void setNo(int No) {
this.No = No;
}
public int getjob_Id() {
return job_Id;
}
public void setjob_Id(int No) {
this.job_Id = job_Id;
}
public String getEmployer() {
return Employer;
}
public void setEmployer(String Employer) {
this.Employer = Employer;
}
public String getjob_Title() {
return job_Title;
}
public void setjob_Title(String job_Title) {
this.job_Title = job_Title;
}
public String getjob_Description() {
return job_Description;
}
public void setjob_Describtion(String job_Description) {
this.job_Description = job_Description;
}
public String getclosing_Date() {
return closing_Date;
}
public void setclosing_Date(String closing_Date) {
this.closing_Date = closing_Date;
}
}
Controller.java
/**
* @author www.javaworkspace.com
*
*/
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.*;
import javax.servlet.http.*;
import DB.*;
import java.sql.*;
import java.io.*;
import java.util.*;
public class Controller extends HttpServlet {
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
List list = new ArrayList();
HttpSession httpSession = request.getSession();
String Cat = request.getParameter("param");
String Category ="Sales";
try {
Connection con = null; // Database connection
DataAccess da = new DataAccess();
da.getConnection();
//pagingData pd = new pagingData();
if (request.getParameter("param")== null)
{
ResultSet rs =da.runQuery("select * from job_Table");
while (rs.next()) {
int No1 = Integer.parseInt(rs.getString("No"));
int job_Id1 = Integer.parseInt(rs.getString("job_Id"));
String Employer1 = rs.getString("Employer");
String job_Title1 = rs.getString("job_Title");
String job_Description1 = rs.getString("job_Description");
String closing_Date1 = rs.getString("closing_Date");
list.add(new pagingData (int No1 , int job_Id1 , String Employer1 , String job_Title1 , String job_Description1 ,String closing_Date1));
//list.add(new pagingData (2 , 1 , "a" , "s" , "s" ,"a"));
}//while
request.setAttribute("pagingList", list);
} //if
else
{
ResultSet rs2 =da.runQuery("select * from job_Table where Category = '"+Cat+"' ");
while (rs2.next()) {
int No2 = Integer.parseInt(rs2.getString("No"));
int job_Id2 = Integer.parseInt(rs2.getString("job_Id"));
String Employer2 = rs2.getString("Employer");
String job_Title2 = rs2.getString("job_Title");
String job_Description2 = rs2.getString("job_Description");
String closing_Date2 = rs2.getString("closing_Date");
list.add(new pagingData(int No2,int job_Id2,String Employer2,String job_Title2,String job_Description2,String closing_Date2));
//list.add(new pagingData (2 , 1 , "a" , "s" , "s" ,"a"));
}//while2 //request.setAttribute("pagingList", list);
} //else2
}
catch (Exception e)
{
e.printStackTrace();
}
httpSession.setAttribute("pagingList", list);
RequestDispatcher dispatcher = request.getRequestDispatcher("/displayjobs.jsp");
dispatcher.forward(request, response);
}
}