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

Reload page without losing data

 
Wilfred D'Souza
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a JSP which has a select box (which has data retrieved from a database). On the selected value of that box another select box (on the same page) should get updated from another database.
Could anyone help me on this one.
Thanx
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JSP since it is better then using JavaScript to solve the problem...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two approaches come to mind:
1) The onselect handler of the select box resubmits the page whose server-side controller (preferable a servlet rather than JSP-embedded Java) interacts with the Model (or DB) to get the values for the second box. The page redraws itself with these values.
2) The onselect handler of the select box submits a request into a hidden iframe that does the DB dirty work and returns as its response a gaggle of Javascript that rewrites the options of the second select box.
Pick your poison.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another possible approach (which works best if the total dataset for all possible fills of the second box is not too large and fairly static) is to preload everything in a series of Javascript arrays and fill the second box using Javascript on the fly.
That's what I usually use as we want in our app to minimise backend calls (which have to run through a middleware layer over the network to software running on another machine which does the actual database access, in all a fairly expensive procedure).
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Jeroen.
If the information that preloaded into the JavaScript can be explored to public, it is a better option. You even can store the list into the session, so that every page that needs this does not require to query the DB via expensive backend calls.
Of course, if the information cannot be preloaded, the only way is to check with the backend server every time.
Nick.
 
Wilfred D'Souza
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx guyz,
I will try all of ur suggestions and let u know if I succeeded.
Thanx once again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic