File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Page Refreshes and re-use of data

 
Ron Olson
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13048
6
  • 0
  • Mark post as helpful
  • send pies
  • 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 agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic