Link to home
Create AccountLog in
Avatar of EmailSurfer
EmailSurfer

asked on

Testing for required input in servlet?

Hello,

I am using javascript in my .jsp pages to check if the user entered data in the required fields.

I wondered if most developers also tested in servlet, incase javascript did not work? Or if this was not required anymore since javascript part of most modern browsers.

I am using this code in my jsp.

<form method="post" action="loginservlet" onsubmit="return validate(this);">

Could I test in the servlet if the onsubmit was successfull?

Thanks
Avatar of avinthm
avinthm

You can use javascript to test user input and  this is faster too.
Sending request to server and getting back the result will take lot of time.

> incase javascript did not work?
this means that your script is not proper or a possible bug in it.

> Could I test in the servlet if the onsubmit was successfull?
you can validate in servlet also, but i would suggest u to write javascript for user input validation.
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I completely (but respectfully) disagree ;-)
I agree with Tim ;-) , best to check in a servlet.. safer and secure.. No time to hack those javascript login ;-D

-Muj ;-)
Avatar of EmailSurfer

ASKER

Thanks

Could I ask finally,

In javascript are there any methods similar to java's indexOf, for example so I could check a email field contains a @ and . characters.

I would also further check for these in the servlet, just incase javascript is switched off.
http://www.w3schools.com/js/js_obj_string.asp

you will find javascript examples here