This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JSP and the fly likes Populating drop down from Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Populating drop down from Database" Watch "Populating drop down from Database" New topic
Author

Populating drop down from Database

rudresh kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 83
HI All,

I have few doubts,
1.I have an application in which some 10 jsp's are there, each having many dependencies, how can this drop down selection be made easier and high performance.
Example
Country -- List of countries
State -- List of states of that country
City -- List of Cities of that state.
Data has to be pulled from database smiliarly checkboxe values has to be pulled from database
2.I have many validations for submitting the form, how can we judge which one to put on client and which one on server (like mandatory fields and business rules).

Thanks in advance
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Retrieve the DB values in a servlet and attach them in a scope. Then forward to the JSP and display them. What validations need to be on the client/server depends on your scenario. Alternatively you could also use AJAX to do it. Would be pretty efficient and fast but needs more coding and you have to explore that area. Like stuff where your javascript etc etc have to conform to MVC for better code maintainance


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

For the dependent drop-downs, Ajax can be used to fetch the data for each subsequent drop-down when a selection is made from the previous one.

The validation question is easier: all data must be validated on the server. Always!

You can perform client-side validation in order to give your user quicker feedback, but regardless of whether client-side validation takes place the data must be validated on the server.
[ March 31, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
rudresh kumar
Ranch Hand

Joined: Jan 04, 2006
Posts: 83
HI,

But this is a huge transaction oriented application (webservices) where >100 validations has to be done and speed also less (100kb)
Still need to go for Server side ?


Thanks
Rudresh
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60732
    
  65

Originally posted by rudresh kumar:
Still need to go for Server side ?


Always. Absolutely. Always. Without question. Always. And did I mention always?

Data from the client can never be trusted -- it's too easy for everybody from script kiddies to malicious hackers to spoof requests to your site. Ignoring data validation on the server opens your site up to a variety of security concerns.

Likewise any user-entered data must always be checked for cross-site scripting attacks and must be HTML-encoded when displayed on a page. What will happen, for example, if a user enters the string "</HTML>" as a data value that you later emit, unencoded to the page?
[ March 31, 2007: Message edited by: Bear Bibeault ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Populating drop down from Database
 
Similar Threads
how jsf component get the value from backing bean instead of submitted value after validation error
2 Select Box`s on one page, second needs to load dynamically
select values for second drop down
Auto generate drop down list
How to retrieve data from database when ever select in drop down list?