• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Resfresh page and getting values when option is selected

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wants to know that is it possible that, when i select the option from drop-down menu on jsp page ,it sends it on servlet and return back to same page with results as per option was selected.

Like, if I am selecting country name from drop-down menu at a time page is refreshed and the value below that country options which is ,options for cities are available with indian cities!!
I have tried to find but, in each code javascript is their...Is it possible without javascript?
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doing this with JavaScript is the correct and modern way. Back before Ajax, you had to submit and refresh the whole page. You can still do that, but it will make your application looks like it was written 10 years ago.

Sort of like building a car today using a crank in the front to turn the motor.

Do have a valid reason to avoid JavaScript?
 
Ranch Hand
Posts: 344
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most modern sites use Javascript to provide a dynamic interface, almost every browser supports it. Personally I would use the onChange event on the dropdown box and use an Ajax approach to request and display the results. I hate sites that refresh or reload the whole page when you select something; it looks so outdated and clunky. You can write your own ajax code or use some 3rd party solutions.
 
apurv suthar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok..then can you give some advise on how to do this task?
and also that ,can javascript interact with FormBeans to get values from FromBean?
(I don't know javascript, so sorry If you found this questions stupid)
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's a FormBean? It's not part of Servlets or JSP.

In any case, no: JavaScript, which executes on the client after the HTML is generated and delivered as the response, cannot directly interact with Java code running on the server to create that response.

There are likely hundreds to thousands of examples of doing this on the Web. Please search.

If you want to use jQuery for your Ajax and JavaScript needs (you should use a library, Ajax has too many cross-browser nuances to do it yourself) you can grab the free sample source code for my jQuery book. The code for chapter 8 shows how to use Ajax and JSP to populate dropdowns dynamically
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, and if you want to understand how JSP works and why it cannot interoperate with JavaScript, I suggest reading this article.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can do that very easilye using javascript like this..

run this code...

 
apurv suthar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you .. I got it..Ajax is necessery for this kind of problems and its a modren day design approach.I will try to follow the same in my project also.
 
apurv suthar
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone says that how to do the same using struts? because, when i am doing




and define the same demo() function as per above code , it doesn't gives any thing....code remains same!!
 
    Bookmark Topic Watch Topic
  • New Topic