Forums Register Login

Validate fields with JavaScript or Servlet?

+Pie Number of slices to send: Send
Hi All,
My question is in 2 parts:
First, I was wondering if there is any benefit to validating a field using JavaScript or just letting the servlet do it? I want to first make sure the field is not blank before invoking the servlet. I was thinking that performance wise, this approach would be better, but I don't know. What do other's think.
Also, if I did allow JavaScript to validate the fields, how would I go about doing this? The form always tries to invoke the servlet before calling the JavaScript function. Is this possible to do?
Thanks for your help!
Barry
+Pie Number of slices to send: Send
Please disregard the second part of the question. I figured that one out. I would still like thoughts on the first though.
thanks,
Barry
+Pie Number of slices to send: Send
About your first question: You should validate every field in your servlet. To do it using javascript is good for avoiding a lot of incorrect requests but javascript is really easy to 'bypass'. Everyone could call the servlet just writing the url in the address bar.
Best solution: Validate twice. Client and Server -side.
HTH
+Pie Number of slices to send: Send
Yes, I never thought about that. Good point!

thanks,
Barry
+Pie Number of slices to send: Send
Hi Barry,
I would like to recommend that you use Struts (because I know someday you will, so why not do it now ), wherein you could automatically enable form validation using ActionForm objects. This will let you separate validation from your main business code (which is cool ). Usually what I do is double-layer validation - on the client side using JavaScript and on the server side using ActionForm objects. Either way it's a win-win situation.
Ex Animo Java!
-- Val
[ July 28, 2002: Message edited by: Val Pecaoco ]
+Pie Number of slices to send: Send
Hai
Yes I agree with My friend Mr.Val Pecaoco has pointed out. Struts gives you a frameowrk to do all of ur validations. Its very simple to learn also. You can set your own error messages for one particular validation.
visit http://jakarta.appache.org/struts/
for more information.
regards Georgie
+Pie Number of slices to send: Send
I agree with the above posts -- I'd put it in JavaScript so that validation occurs on the Client-side (avoids processing on the server-side). However, if someone has JavaScript disabled -- you're hooped, so definately re-validate it on the Server-Side with Struts (will give you a new technology to learn/master too!)
----------------------------------------
"georgejk"-
Welcome to the JavaRanch! Please adjust your displayed name to match the JavaRanch Naming Policy.
You can change it here.
Thanks! and again welcome to the JavaRanch!
Do not threaten THIS beaver! Not even with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1541 times.
Similar Threads
What is good practice for FORM VALIDATION ?
How to validate text fields after enter key press
validating that field has a number
losing data when user enters form value with double quotes
servlet doubt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 22:04:40.