A Page tracking system…

Using server faces its possible to store up the pages a user has visited in an order. This was useful for me because I needed one page to be called from a lot of other places and “javascript:history.back()” wasn’t working because when the user clicks buttons on the page, the back page is the last one!.

So first setting up the session bean.

In the session bean I added a public string.

    public String[] sURL={"","","","",""};

And some functions to support it:-

public void StoreURL(String sURLtoSearch) {
// this routine keeps a history of 5 urls
// that the user has visited
// so that we can correctly link back to the last one
if (sURL[0].equals(sURLtoSearch)) {
// its different lets do the shuffle
for (int i=4;i>0;--i) {
public String getURLs() {
String result="";
for (int i=0;i<5;++i) {
return result;
public String getLastPage() {
// returns the last page visited
return sURL[0];

Then on the the pagefragment I have on all the pages (header) I added the code:-

HttpServletRequest request= (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
try {
 String sURL=request.getRequestURL().toString();


} catch (Exception e) {

I’ve left it pretty for you but its now down to one line.

Then lets say I have a Hyperlink I want to link back to the last page…

hypWHEREFROM.setUrl(getSessionBean1().getLastPage() );

And off we go.


About Paul C

I am a Senior Java programmer/Web Technologies, Play in a band called Mandolin Monday, I have a cat and I live on a boat.

Posted on April 23, 2008, in Uncategorized. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: