Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • 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
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

populating a field automatically  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an address page where I want to be able to populate the city field when a user enters a zipcode. what is the best way to do this. Keep in mind that I have to query a db when I get the zipcode to retrieve the city
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about having your JSP page submit to a servlet when a "Verify Zip Code" button is pressed? The servlet could then use JDBC, or a similar technology, to look up the zip code in the database. If found, it would store the corresponding city in the session context and forward the request to your JSP. Your JSP would then serve the page with the City field filled in.

Jules
 
Marshal
Posts: 67226
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

it would store the corresponding city in the session context



I would add that unless this value needs to have a lifetime well beyond the current page, storing the value in the request context would be preferred.
 
bronco
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a quick thought...you could probably use a little javascript to kick off the server-side call when they exit the field rather than making them click a button. Might be a slightly better user experience.

(ideally, use javascript to make sure the zip code field has 5 or 9 digits in it before calling the server at all, otherwise you'll annoy people who tab out of the field without entering anything)
 
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!