Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep object througe pages

I'm working on a web project. The flow is like this

  1. User inputs the parameters
  2. Call to servlet is made (post method)
  3. The servlet loads a large file (300.000 lines , one word per line) in a tree object. Does some calculations.
  4. Redirects to a new page for the results.

My question is this. The user may do this operation more than once. The loading of the file to the tree object is taking too long. How can I do this, only once? I've thought to have just one servlet (or jsp) and not redirecting to different pages, but manipulating the view with javascript. This way I think that I will manage to load the file only once (and whenever the user refreshes). Do you have any suggestions?

EDIT 1. This object is created by a class that is called from the servlet. I'm using apache tomcat 7 and java 1.6 . HTML5 is an option too (someone mentioned the history api).

like image 307
Alkis Kalogeris Avatar asked Jul 17 '26 16:07

Alkis Kalogeris


1 Answers

Is the file specific to the user ? Keep the object in the user's session.

If its common to many users and they only need to read/ view this data keep it in the application object.

If your talking about the view -> browser then yes the way to do is ajax and/or frames and/or iframes

Advantage with frames is you can keep the data in another farme and still access it from other pages, but change the main view area to another page completely


Detail user's session : available in servlets, filters, jsps etc -> key Object pair. can have any number of keys and objects but remember its all in the RAM, until session expires or if it is explicitly destroyed.

http://docs.oracle.com/cd/E19502-01/819-3669/bnaij/index.html

How to use the "application" object in a Servlet?

Application level http://docs.oracle.com/javaee/5/api/index.html?javax/servlet/jsp/PageContext.html get and setAttribute(String name, Object object) This object can be read in all pages and jsps. Need to take care if object is already there (getAttribute does not return null) before you do the task of initializing it. Does the main file change? IF so can keep some code that calls a jsps that refreshes it. (like an admin jsp)

Frames/ ajax is for client level and you need to ask a more specific question for this but stack over flow and google have many examples of using this.

like image 136
tgkprog Avatar answered Jul 20 '26 06:07

tgkprog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!