Working with JSP Sessions
December 13th, 2007No Comments | Filed Under: Tutorials
* getCreationTime —returns value of time in milliseconds.
* getLastAccessedTime—returns the value of time in milliseconds.
* getId—method of session object is used to return the unique identifier associated with the session.
* invalidate()
* getMaxInactiveInterval
* setMaxInactiveInterval()
* removeAttribute(String name)
* setAttribute(String, object)
Checking the results of a ResultSet
December 13th, 2007No Comments | Filed Under: Tutorials
boolean recordsWereFound = false;
while (rs.next()) {
recordsWereFound = true;
// process this record;
}
if (! recordsWereFound) {
// do this if no records were found
}
forward from one application to other application
December 13th, 2007No Comments | Filed Under: Tutorials
The number of ways in which we can forward from one application to another application running on different containers.I think these 2 can work :
1.ServletContext.getRequestDispatcher.forward(“URL of the 2nd application”)
2.response.sendRedirect(“URL”)
Pagination in JSP/Java
December 13th, 20074 Comments | Filed Under: Tutorials
Here i’m going to write, how to do pagination in Java. The situation is first count how many rows in the database table, then query the database by page size (how many rows you want to display on a web page).
In Jsp
int pageno=0;
if(pno==null)
{
pageno=1;
}
else
{
pageno=Integer.parseInt(pno);
}
int next=pageno+1;
int previous=pageno-1;
//Java method
ArrayList al=object.getData(pageno);
// do all your showing data logic here
//print the previous and next links
if(previous!=0){
Previous link (url.jsp?pno=previous)
}
int max=obj.getTotalRows(); // total number of rows from database table
int check=(next-1)*10; // each page 10 rows
if(check<max){ // print next link if check is less than total rows
Next link (url.jsp?pno=next)
}
In Java
public ArrayList getData(int pagenumber)
{
ArrayList al=new ArrayList();
int offset = (pagenumber – 1) * 10;
//write all the logic and query data with the limit offset
Query + limit offset ,10;
return al;
}
//for getting total rows
public int getTotalRows() {
//write your logic to get total count of the rows
Query total rows from db table
return total_rows;
}

