views:

725

answers:

3

How we can validate the our jsp form before storing the data in database

+1  A: 

By using validators.

Dev er dev
Indeed - "by checking that the input is valid".
Andrzej Doyle
Marko, while your answer may be 100% correct, I'd edit to add a link to some site on the web with more information... would be a lot more helpful to the asker, dontcha think? =8-)
Yuval
Given the question itself and info provided in it, this answer is all I can offer :)
Dev er dev
+1  A: 

Depends on the framework you are using. If you are developing bare Servlets - you can build your own validator framework (each entity should have a separate class holding validation code for that entity)

If you are using some framework (Struts, Spring, etc), you should check their documentation.

miceuz
A: 

Depending on the validation needed, a better approach might be to validate the data on the client (perhaps using Javascript). It'll save a server-client trip and will provide users with immediate feedback.

Zabbala
This requires server-side validation as well. Client-side is an optional extra; you need to validate at your application's entry point. Otherwise anyone malicious could just disable Javascript etc etc.
Robert Grant
I agree. But if the validation needed is say: 'username should be 8 characters long or checking the validity of a date entered', a quick JS function could provide immediate feedback. This should not replace any validation done on the server before the interaction with the database.
Zabbala