I need to validate this simple pick list:
<select name='<%= key %>'> <option value='ETC' SELECTED>Select an option...</option> <option value='ONE'>Lorem ipsum</option> <option value='TWO'>dolor sit amet</option> </select>
So the user would never submit the form with the, excuse the repetition, ‘Select an option…’ option selected. In principle I’m allowed to use JavaScript but It’d be interesting to learn how to solve it within JSP too.
You can never really satisfy the condition ‘never submit a given value’ because you don’t have control over the client side. The user can always manipulate HTML to submit whatever they want.
It is a good approach is to use JavaScript to do client-side validation and give the user quick feedback and catch 99%+ of the cases, then do a server-side validation of the submitted parameters to catch the minority that don’t have JS enabled or who manipulate the HTML to submit non-expected values.
Just remember that the client-side validation is optional, and is good for those ‘common mistakes’ input validation, but the server-side validation is mandatory for all input whether or not any client-side checks have been done on the given input.