pagination problem
Thanks sir for posting the answer.But i have 2 problems
1.i have created one employee class in that i use getter and setter methods,i created another class in that i wrote the methods like modify(),delete(),insert() methods using or importing employee class.finally i created a class using servlets in that i called a these methods,to call this servlet i created a html file i wrote one form to call this servlet.
In this servlet i used doget()method in that i created a 2 forms to call a methods like insert() and modify(),my problem is that where i have to put & how to do pagination?
my code as follows.
package com.antares.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Iterator;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.antares.To.Employee;
import com.antares.service.EmployeeDataBase;
@SuppressWarnings("serial")
public class EmployeeCheckServlet extends HttpServlet {
Employee employeeDTO = null;
ServletContext context;
@Override
public void init() throws ServletException {
System.out.println(" Inside EmployeeCheckServlet.init()");
}
Connection connection = null;
Statement statement = null;
ResultSet resultSet = null;
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println(" Inside EmployeeCheckServlet.doGet()");
String strServletPath = request.getServletPath();
response.setContentType("text/html");
PrintWriter out = response.getWriter();
System.out.println("************ Path is " + strServletPath);
try {
String className = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@twtesting:1550:orcl1";
String user = "supplyco";
String pwd = "supplyco";
try {
Class.forName(className);
connection = DriverManager.getConnection(url, user, pwd);
statement = connection.createStatement();
System.out.println("Connection established");
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
if (strServletPath.equalsIgnoreCase("/new.do")) {
out.println("<html>");
out
.println("<body bgcolor='pink'><h3>Hello User Enter The Following.....</h3>");
out.println("<form action='./newuser.do' method='get'>");
out.println("<table>");
out
.println("<tr><td>Enter Your First Name</td><td><input type='text' name='fstname'></td></tr>");
out
.println("<tr><td>Enter Your Last Name</td><td><input type='text' name='lstname'></td></tr>");
out
.println("<tr><td>Enter Your Address</td><td><input type='text' name='add'></td></tr>");
out
.println("<tr><td>Enter Your Phone Number</td><td><input type='text' name='phno'></td></tr>");
out
.println("<tr><td>Enter Your Email ID</td><td><input type='text' name='emailid'></td></tr>");
out
.println("<tr><td>Enter Your Status</td><td><input type='text' name='status'></td></tr>");
out
.println("<tr><td colspan='1' align='center'><input type='submit' value='Click Here To Submit'></td></tr>");
out.println("</table></form></body>");
out.println("</html>");
} else if (strServletPath.equalsIgnoreCase("/newuser.do")) {
String strFirstName = request.getParameter("fstname");
String strLastName = request.getParameter("lstname");
String strAddress = request.getParameter("add");
String strPhoneNumber = request.getParameter("phno");
String strEmailId = request.getParameter("emailid");
String strStatus = request.getParameter("status");
int intPhoneNumber = Integer.parseInt(strPhoneNumber);
System.out.println("**** FIRST NAME IS ****"+strFirstName);
employeeDTO = new Employee();
EmployeeDataBase empDB = new EmployeeDataBase();
employeeDTO = empDB.insertEmployeeDetails(strFirstName,
strLastName, strAddress, intPhoneNumber, strEmailId,
strStatus);
ResultSet resultSet = null;
boolean blnIsValid = false;
try {
resultSet = statement
.executeQuery("SELECT * FROM EMPLOYEE");
while (resultSet.next()) {
if ((strFirstName.equalsIgnoreCase(resultSet.getString("EMP_FIRSTNAME")))
&& (strLastName.equalsIgnoreCase(resultSet.getString("EMP_LASTNAME")))
&& (strAddress.equalsIgnoreCase(resultSet.getString("EMP_ADDRESS")))
&& (strPhoneNumber.equalsIgnoreCase(resultSet.getString("EMP_PHONENO")))
&& (strEmailId.equalsIgnoreCase(resultSet.getString("EMP_EMAILID")))
&& (strStatus.equalsIgnoreCase(resultSet.getString("EMP_STATUS")))) {
blnIsValid = true;
break;
}
}
if (blnIsValid) {
out.println("<html>");
out.println("<body bgcolor='pink'>");
out.println("<h3>Your Personal Details As Follows :</h3>");
out.println("<br>Your Emp_id :"+ resultSet.getInt("EMP_ID"));
out.print("<br>Your First Name :" + strFirstName);
out.print("<br>Your Last Name :" + strLastName);
out.print("<br>Your Address :" + strAddress);
out.print("<br>Your Phone Number :" + strPhoneNumber);
out.print("<br>Your Email ID :" + strEmailId);
out.print("<br>Your Status :" + strStatus);
out.print("<br><br><br> <a href='./empsumm.do'>Click Here To Go Employee Summery </a>");
out.println("</body></html>");
}
else {
out.println("<html>");
out.println("<body bgcolor='babypink'>");
out.println("<h3>Sorry User Your Details Arenot Correct Please Enter Once Again!!!!!!!!</h3>");
out.println("</body></html>");
}
} catch (SQLException e) {
e.printStackTrace();
}
}
else if (strServletPath.equalsIgnoreCase("/empsumm.do")) {
out.println("<html>");
out.println("<body bgcolor='wheat'><center><h3>Following Are List Of Employees.....</h3></center>");
out.println("<form action='./modify.do' method='get'>");
out.println("<center><table border='2'cellpadding='7' cellspacing='1'>");
out.println("<tr><td>Select</td><td>EmpId</td><td>First Name</td><td>Last Name</td><td>Address</td><td>Phone Number</td><td>EmailID</td><td>Status</td>");
EmployeeDataBase empDB = new EmployeeDataBase();
ArrayList<Employee> arlEmp = empDB.findAllEmployees();
Iterator<Employee> iter = arlEmp.iterator();
int intEmpId = 0, intEmpPhoneNo = 0;
String strFstName = null, strLstName = null, strEmpAdd = null, strEmailId = null, strStatus = null;
while (iter.hasNext()) {
Employee empDTO = (Employee) iter.next();
intEmpId = empDTO.getIntEmpid();
strFstName =empDTO.getEmp_fristName();
strLstName=empDTO.getEmp_lastName();
strEmpAdd = empDTO.getEmp_address();
intEmpPhoneNo = empDTO.getEmp_phone();
strEmailId = empDTO.getEmp_email();
strStatus = empDTO.getEmp_status();
System.out.println();
out.println("<tr>");
out.println("<td><input type='radio' value='"+intEmpId+"' name='empid'></td>");
out.println("<td>" + intEmpId + "</td>");
out.println(" <td>" + strFstName + "</td>");
out.println(" <td>" + strLstName + "</td>");
out.println(" <td>" + strEmpAdd + "</td>");
out.println(" <td> " + intEmpPhoneNo + "</td>");
out.println(" <td>" + strEmailId + "</td>");
out.println("<td>" + strStatus + "</td>");
out.println("</tr>");
}
out.println("</table><br><br><input align='right' type='submit' value='To Modify'></form></center><form action='./new.do' method='get'><center><input type='submit' value='New User'></center></form>");
out.println("<form action='./delete.do' method='get'><center><input type='hidden' value="+intEmpId+" name='empid'>");
out.println("<input align='right' type='submit' value='To Delete'></center></form>");
out.println("</body>");
out.println("</html>");
} else if (strServletPath.equalsIgnoreCase("/modify.do")) {
String strEmpId = request.getParameter("empid");
System.out.println("******* empid Is ******" + strEmpId);
int intempid=Integer.parseInt(strEmpId);
String strFstName = null;
String strLstName = null ;
String strEmpAdd = null ;
int intEmpPhoneNo = 0 ;
String strEmailId = null ;
String strStatus = null ;
ResultSet resultSet=null;
resultSet=statement.executeQuery("SELECT * FROM EMPLOYEE WHERE EMP_ID="+strEmpId);
while(resultSet.next())
{
//intEmpId1 = resultSet.getInt("EMP_ID");
strFstName = resultSet.getString("EMP_FIRSTNAME");
strLstName = resultSet.getString("EMP_LASTNAME");
strEmpAdd = resultSet.getString("EMP_ADDRESS");
intEmpPhoneNo = resultSet.getInt("EMP_PHONENO");
strEmailId = resultSet.getString("EMP_EMAILID");
strStatus = resultSet.getString("EMP_STATUS");
}
out.println("<html>");
out.println("<body bgcolor='orange'><h3>To Modify Anything Enter The Following</h3>");
out.println("<form action='./modifytable.do' method='get'>");
out.println("<table>");
out.println("<tr><td>EmpId</td> <td><input type='text' value="+strEmpId+" name='empid'></td> </tr>");
out.println("<tr><td>Enter First Name</td> <td><input type='text' value="+strFstName+" name='fstname'></td> </tr>");
out.println("<tr><td>Enter Last Name</td> <td><input type='text' value="+strLstName+" name='lstname'></td> </tr>");
out.println("<tr><td>Enter Address</td> <td><input type='text' value="+strEmpAdd+" name='address'></td> </tr>");
out.println("<tr><td>Enter PhoneNumber</td> <td><input type='text' value="+intEmpPhoneNo+" name='phone'></td> </tr>");
out.println("<tr><td>Enter EmailId</td> <td><input type='te"+ "xt' value="+strEmailId+" name" + "='emailid'></td> </tr>");
out.println("<tr><td>Enter Status</td> <td><input type='text' value="+strStatus+" name='status'></td> </tr>");
out.println("<tr><td colspan='1' align='center'><input type='submit' value='Click Here To Submit'></td></tr></table></form>");
out.print("<br><br> <a href='./empsumm.do'>Click Here To Go Employee Summery </a>");
out.println("<br><br><h3>DO You Want To Delete A Record.</h3><form action='./delete.do' method='get'><center><input type='hidden' value='"+intempid+"' name='empid'><input align='right' type='submit' value='To Delete'></center></form>");
out.println("</body><html>");
} else if (strServletPath.equalsIgnoreCase("/modifytable.do")) {
String strEmpId=request.getParameter("empid");
System.out.println("******VALUE OF EMPID IS*****" + strEmpId);
String strFirstName = request.getParameter("fstname");
String strLastName = request.getParameter("lstname");
String strAddress = request.getParameter("address");
String strPhoneNumber = request.getParameter("phone");
String strEmailId = request.getParameter("emailid");
String strStatus = request.getParameter("status");
int intPhoneNumber = Integer.parseInt(strPhoneNumber);
employeeDTO = new Employee();
EmployeeDataBase empDB = new EmployeeDataBase();
int intEmpId = Integer.parseInt(strEmpId);
System.out.println("******VALUE OF EMPID IS*****" + intEmpId);
employeeDTO = empDB.modifyEmployee(intEmpId, strFirstName,
strLastName, strAddress, intPhoneNumber, strEmailId,
strStatus);
boolean blnIsValid = false;
resultSet = statement.executeQuery("SELECT * FROM EMPLOYEE");
while (resultSet.next()) {
if ((strFirstName.equalsIgnoreCase(resultSet
.getString("EMP_FIRSTNAME")))
&& (strLastName.equalsIgnoreCase(resultSet
.getString("EMP_LASTNAME")))) {
blnIsValid = true;
break;
}
}
if (blnIsValid) {
out.println("<html>");
out.println("<body bgcolor='pink'>");
out.println("<h3>After Modification Your Personal Details As Follows :</h3>");
out.println("<br>Your Emp_id :"+ resultSet.getInt("EMP_ID"));
out.print("<br>Your First Name :" + strFirstName);
out.print("<br>Your Last Name :" + strLastName);
out.print("<br>Your Address :" + strAddress);
out.print("<br>Your Phone Number :" + strPhoneNumber);
out.print("<br>Your Email ID :" + strEmailId);
out.print("<br>Your Status :" + strStatus);
out.println("<br><br> <a href='./html/login.html'> Click Here To Go Home Page </a>");
out.println("<br><br> <a href='./empsumm.do'>Click Here To Go Employee Summery </a>");
out.println("</body></html>");
}
}
else if (strServletPath.equalsIgnoreCase("/delete.do")) {
String strEmpId = request.getParameter("empid");
System.out.println("******* empid in delete method Is ******" + strEmpId);
out.println("<html>");
out.println("<body bgcolor='skyblue'><form action='./rowdelete.do' method='get'>");
out.println("<h3>Are You Sure Want To Delete The Record....Where Emp_Id="+strEmpId+"</h3><input type='hidden' value='"+strEmpId+"' name='empid'><input type='submit' value='Yes'>");
out.println("<br><br> <a href='./empsumm.do'>Are Else Click Here To Go Employee Summery </a>");
out.println("</body></html>");
}
else if (strServletPath.equalsIgnoreCase("/rowdelete.do")) {
String strEmpId=request.getParameter("empid");
int intEmpId = Integer.parseInt(strEmpId);
EmployeeDataBase empDB = new EmployeeDataBase();
empDB.deleteRow(intEmpId);
out.println("<html>");
out.println("<body bgcolor='+9999-999123blue'><form action='rowdelete.do' method='get'>");
out.println("<h3>The Employee Details Completely Deleted!!!!!!!!</h3>");
out.println("<br><br> <a href='./html/login.html'> Click Here To Go Home Page </a>");
out.println("</body></html>");
}
} catch (SQLException e1) {
e1.printStackTrace();
} finally
{
if(resultSet!=null)
{
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(statement!=null){
try {
statement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
@Override
public void finalize() throws Throwable {
if(connection!=null)
{
try {
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
2.please tell me the how to do the delete().i done but it is accessing the last row employeeid ,so how to get the empid of which we are clicking to delete.
View Answers
March 24, 2010 at 4:19 PM
Hi Friend,
Please post your full code.
Thanks
Related Tutorials/Questions & Answers:
pagination problem - JSP-Servlet(),my
problem is that where i have to put & how to do
pagination?
my code...
pagination problem Thanks sir for posting the answer.But i have 2 problems
1.i have created one employee class in that i use getter and setter
pagination problem - JSP-Servlet(),my
problem is that where i have to put & how to do
pagination?
my code...
pagination problem Thanks sir for posting the answer.But i have 2 problems
1.i have created one employee class in that i use getter and setter
Advertisements
Checkbox pagination problemCheckbox
pagination problem HI .,
Following is my code
test.jsp
<%@page import="java.sql.*"%>
<%@taglib prefix="c" uri="/WEB-INF/c-rt.tld" %> ADS_TO_REPLACE_1
<%@page import="java.util.HashMap"%>
<
PaginationPagination How to create
pagination in jsp with EJB using MS SQL
PaginationPagination How to implement
pagination in struts using hibernate
PaginationPagination How to apply
pagination in JSP.
Please help
paginationpagination How to set
pagination using java script to display data
paginationpagination Simple way for
pagination in jsp using java script to display data without send database
PaginationPagination Is their plug n play approach for creating
pagination?
1) Server side as well as client side
PaginationPagination I want to write one where condition in sql query in
pagination concept
PaginationPagination I want to know how to use
pagination in jsp.
I have a list object from that i want to display 3 questions per page
can u help me
paginationpagination I need to give
pagination with where condition (query="select * from qtn where qid='"+replyQuesionId+"'limit "+iPageNo+","+showRows+"" ) like this I want, without where condition it is working but with condition
pagination code of
pagination. In the given code,we have taken the database table student...;
Pagination of JSP page</h3>
<body>
<form>
<input type="hidden... for you.
here
problem is that : suppose i have 10 questions and i
paginationpagination I need to give
pagination with where condition (query.......
Here is a simple jsp
pagination code where we have used mysql database...()) {
totalRows=rs2.getInt("cnt");
}
%>
<html>
<h3>
Pagination of JSP
Pagination=rs2.getInt("cnt");
}
%>
Pagination of JSP page
Terr_Code
Terr_Name
paginationpagination how can i start
pagination in jsp?
Hi Friend,
Try the following code:
<%@ page language="java" %>
<%@ page import...;
Pagination of JSP page</h3>
<body>
<form>
<input type="hidden
PaginationPagination
pagination in jsp
Hi Friend,
Try the following code:
<%@ page language="java" %>
<%@ page import="java.sql.*" %>...()) {
totalRows=rs2.getInt("cnt");
}
%>
<html>
<h3>
Pagination of JSP
Pagination in javaPagination in java How to handle
pagination when there are records like say in millions in java? Or do we handle this using SQL? I as asked... far good performance then Java
pagination.
Thanks
pagination in php - Ajaxpagination in php i want to fetch my data base in view page...i hav done
pagination...
i don't want the order....like...
1
2
3
4... the
problem in ordering
please give me a solution.. Hi Friend,
You
pagination in jsfpagination in jsf Hi ,
i am implemeting an online exam system , i have placed my questions as an arraylist in my jsp file within tag , but now i want to paginate these questions based on respective questions by clicking
jsp paginationjsp pagination I want to implement
pagination on jsp page Each jsp page having some radio buttons, on click of next previous page selected radio buttons are reset. I want to maintain state of selected radio buttons on previous
JSP Pagination to be shown, I want to implement
Pagination.. Can someone show me a sample code which I could possibly use??
JSP
Pagination
pagination.jsp:
<%@ page...");
}
%>
<html><h3>
Pagination of JSP page</h3>
<body><
jsf pagination of
pagination. In the given code,we have taken the database table student(rollNo,name,marks...()) {
totalRows=rs2.getInt("cnt");
}
%>
<html>
<h3>
Pagination of JSP
JTable PaginationJTable Pagination Hello , I have the following Code. I am able to fetch the Data from the Database. But i need to implement
pagination for the same. Can someone please help me out with this ? I have tried out many things from
Two Pagination in one pageTwo
Pagination in one page hai friends any one help me.
how do u make two
pagination script in same page i'm used some ajax coding one
pagination script is working but another
pagination is not working please help me urgent
Pagination with condition using servlet or jspPagination with condition using servlet or jsp Hi,
Thanks...")", Then I want perform the
pagination based on the string value(I mean
pagination with condition). My
problem is first time five records will come(I mean 5 records
pagination - JSP-Servletpagination Hi,
could u tell me how i will handle
pagination... friend,
Simple
pagination in jsp
Simple
pagination in JSP...
Simple
pagination in jsp
Displaying Records
pagination in jsp - JDBCpagination in jsp Hi,
I have millions of records in my oracle d... in advance...
Hi friend,
This is simple code of
pagination.
Simple
pagination in jsp
Pagination in PHP code - PHPPagination in PHP code 3.Pagination in PHP codeIs it possible to get the paging in PHP without database call? How will I show the image instead of numbering? any code that can help
Pagination in struts 2Pagination in struts 2 Hi,
I have one question regarding
pagination in struts 2 I saw one of your code that you explain here:- http... me or guide me what other option i have to use
pagination in struts 2 without