• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Page Refreshes and re-use of data

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My question deals with the flow of data between Servlets and JSP pages, and how to deal with a page that is Refreshed by a user. My flow for a database-driven page is this:
1) Servlet accesses the database, bundles up the raw data needed for the eventual HTML creation, and stores that data in session variables.
2) Servlet redirects to a JSP page
3) JSP page takes the raw data from session variables, and creates the HTML from it.
But, what happens when the user refreshes that same page? It seems to me that I have two choices, each with pros and cons.
1) The JSP page can release the data once it's created its HTML. Then, when the servlet reruns, it starts from scratch, recreating the raw data from the database.
or
2) The JSP page can leave the data intact in the session variables. Then, when the servlet reruns, it can re-use the session data, thus avoiding recreating it from the database. But, in so doing it must somehow determine if this 2nd request is a repeat or something new, so that it will know if the saved data is usable or new data is needed.
Can anyone out there offer your experience on how best to deal with this?
Ron
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just have the JSP add a marker object to the session the first time it is used. If that object is there, this is not the first access.
if( session.getAttribute("used") == null ){
session.putAttribute("used","used");
}
else { // reused
}
------------------
author of:
 
I think she's lovely. It's this tiny ad that called her crazy:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic