aspose file tools*
The moose likes Servlets and the fly likes Refreshing/Reloading JSPs when user hits Back button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Refreshing/Reloading JSPs when user hits Back button" Watch "Refreshing/Reloading JSPs when user hits Back button" New topic
Author

Refreshing/Reloading JSPs when user hits Back button

Mallika Kumar
Ranch Hand

Joined: Feb 15, 2001
Posts: 61
Hi,
I have a query tool which shows specified number of rows of data per page(the number of rows chosen by the user). When the user enters some info into the form fields in the first page, I'm storing those values in the session, and calling the result page repeatedly till all rows are obtained. Now, when the user hits the back button from result page, and enters some other info into the form fields and clicks on submit button(in the first page), it executes the previous query, and not the new one whose values have been entered. I'm removing the session variables in the first page. But unless the user hits Refresh or Reload buttons in the first page, the session variables are not removed. I tried using META HTTP-EQUIV REFRESH tag in the header of the first page, with a value of 30 seconds. But this does not seem reliable. What if the user performs a query, then hits the back button, and performs another query, within 30 seconds ?
Is there a way to reload a jsp page when the user hits the Back button and gets to it ?
Any suggestion would be welcomed.
Thanks a lot.
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

To be honest, I'm not perfectly clear from your post what you are trying to do exactly, but it sounds like you could change the scope of whatever is having the problem from session to request.
It might also help to step through the logic and see when variables need to be available and persistant or when you need to reset them. Probably some small changes in the design will fix this.


!_I_Know_Kung_Fu_!
Mallika Kumar
Ranch Hand

Joined: Feb 15, 2001
Posts: 61
Hi Andrew,
This is what I'm doing......
1. First, the user can enter some input fields in a form page and submit to a result page.
2. I'm validating(checking for null-ness) in the result page. If the user did not enter any values and hit submit, I'm forwarding them to the form page.
3. If the user did enter some values, I'm storing these in the session.
4. Executing the query based on the user entered values.
5. If the results span more than one display page, I'm calling the result page repeatedly till all rows have been displayed.
6. For displaying rows, I'm using a session scoped bean, and for the query, I'm using a page scoped bean.
7. If the user gets some rows in one query, then goes BACK to the form page and enters some other values to get another query, I'm getting the first query as its input values have been stored in the session.
8. I'm removing the session values in the form page, but, as I explained earlier,unless the user hits Refresh/Reload, the session values will not be removed.
9. Using meta tags does not seem the proper solution to me, coz its based on time intervals, and the behaviour will be the same as I described above until that time has elapsed.
Hope I've clarified myself.......I did go through the design after you suggested, but I think what I'm doing is okay. Of course, it might not be the best, and thats why I'm posting it here, so that I can get some suggestions.
Thanks for the response, and hoping to get more.
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

Ok, I still have a few questions.
At what point do you assign the values from the form to session attributes?
If you make an initial query that has multiple entries, and display a few rows, then go back and try another query, then you see the next possible row from the original query? or the first row from the original?
I think you don't want to remove the session values in the form page. You want to handle it correctly on the request from the form.
Another question, why do you need to assign the values for the query to the session? Why not just make the query and display the results without any session attributes? What is the session object really helping you do?
Mallika Kumar
Ranch Hand

Joined: Feb 15, 2001
Posts: 61

This is whats happening....
1. First query has 5 rows in it.
2. In the result page,after seeing these rows, I go back and enter another value in the form, and execute a new query.(The initially entered form field is left as is, and this field, alongwith the newly entered field,create a new query.)
3. Now the query has 8 rows(5 from first query, and 3 additional rows from second query).
4. I can now see the remaining 3 rows in the result page.
The reason I'm storing the user entered values in the session is:
1. The user enters some values in form page and submits the query.
2. If this has rows to be displayed in many pages, then I'm executing the query for every page. I can't use request.getParameter() in the subsequent calls to the result page, coz it is treated as a new page which is making a call to itself. So, for the first call, I see if request.getParameter()works. If it does, I store it in the session, and execute the query. For all following calls, I use the session values.
I'm using a session bean to display rows coz I need to track the rows which have been displayed, and show the remaining ones in the next call to the resullt page. That is the reason why I'm seeing the remaining 3 rows in the second query,instead of all 8.
How can I get the query to show all 8 rows ?
Thanks.
Andrew Shafer
Ranch Hand

Joined: Jan 19, 2001
Posts: 338

I'm getting more confused about what is happening.

This is whats happening....
1. First query has 5 rows in it.
2. In the result page,after seeing these rows, I go back and enter another value in the form, and execute a new
query.(The initially entered form field is left as is, and this field, along with the newly entered field,create a new query.)
3. Now the query has 8 rows(5 from first query, and 3 additional rows from second query).
4. I can now see the remaining 3 rows in the result page.

So you can only see the 3 rows that correspond to the results of the second query? I thought you said before you still saw the results of the first query.
Let's see the code that displays the results.
vaibhav punekar
Ranch Hand

Joined: Jan 20, 2001
Posts: 134
I think this question suits more to HTML and JAVASCRIPT forum.So why do you not put it in that forum?I think Javascipt will help but do not know how.


VAIBHAV <BR>SCJP
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
Something's not clear to me at all (maybe I've overlooked some vital piece of information). When the user enters values, does he enter them into a form? And when he kicks off the search, does the form get submitted to a servlet/JSP which stores the values in the session and initiates the rest of the process?
If the answer to all of the above is "yes", then why does the form not get submitted the second time around, or if it does, how come you fail to overwrite the old session values with the new ones?
- Peter
Mallika Kumar
Ranch Hand

Joined: Feb 15, 2001
Posts: 61
Hi,
I'm sorry for not describing the problem and what I'm doing clearly. I mis-interpreted the problem in my post initially.....
My first page is a jsp which allows users to enter some fields. I'm posting this to a result jsp,which displays the results.
I have a counter variable which tracks the number of rows being displayed in the result page. Its a member of the session scoped bean which I'm using to show rows.
Supposing I get 3 rows in the first query, and 10 rows in the second query. As my counter has a value of 3,it'll show me rows from 4 to 13 (the initially entered field is left as is,and alongwith the next query's field gets 13 rows in the second query).
Now, if the first query gets 3 rows, and I remove the initially entered query's field, and enter another field(basically not retaining the first entered value), this is also a new query. If it gets me 7 rows, as my counter is already at 13, I get no more rows to be displayed.

Thanks.

Mallika Kumar
Ranch Hand

Joined: Feb 15, 2001
Posts: 61
Hi,
All I had to do was to reset the counter value whenever the user goes back to the first jsp page and enters some other value.
Thanks for the responses.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Refreshing/Reloading JSPs when user hits Back button