Advanced Java Servlet Tutorial #Validation: ============= The process of varifying the pattern & format of form data before its getting use as the input values of businees logic is called as "form validation". If form validations are not done, business logic may generate exceptions or wrong results or null values may be stored in database. We can place form validation logic in two places: ------------------------------------------------ 1) client Side 2) Server Side 1) client Side: 2) Server Side ------------------------------- ------------------------------------- 1) Comes to browser window for 1) Resides and executes in server execution from server, along with by coming part of server side web form page. resource program like servlet/JSP. 2) We can use java script, VB 2) Should be written in Java Code. script & etc for client side validation 3) Java Script is recommended to use. If we place only client side form validation logic it reduces network round trip between client/browser & server/webserver, but there is possibility of disabling script-code/java-scipt code through browser setting. To overcome this problem, write both server and client side form validation logic but make sure that server form validation logic is executes only when client side form validation are not done. Example Web form validation logic: 1) Checking whether required components filled up or not(Required rule). 2) Checking email-id id having . , @ symbol or not & etc... Q. What is the difference between form validation logic & business logic: ========================================================================= Form validation logic just verifies the pattern & format of the form data, whereas the business logic uses the form data as input value and generates the results. Ex: 1) When click on submit button, Checking whether credit card number is given or not before sending the data to server is called as form validation. 2) Taking credit card number and sanctioning amount is business logic. #Q. What is the difference between Java & JavaScript? ==================================================== Java JavaScript ------------------------------------ ------------------------------------ 1) Its the programming language. 1) Its the scipting language. 2) Its object oriented language. 2) Its a object based language(Polymorphim is not avaiable) 3) Code can be executed indepedently 3)This code must embedded with HTML Code for execution 4) Needs JRE/JVM for execution 4) Needs JavaScript engine for execution. 5) Can be used to develop all kinds 5) Useful only in web application. of application Note: The language whose code can not be executed independently & whose code must be embedded with others technologies code for execution is called as "scipting language". Ex: JavaScript, VBScript & etc... Becuase this code must be embedded with HTML for execution. The following are some of the javascript events onClick onsubmit onblur etc... When "Submit" button is clicked "onsubmit" event will be raised. Always call javascript function of form validation with return statment against "onsubmit" event. eg: form action="vturl" onsubmit="return validate(this)" --------- *1 --------- /form *1 Here return statment return value of validate(-) function like true/false sends to browser window. If "true" (no form validation errors) then browser window sends the request to server based on the action url (action="vturl") If "false" (form validation errors are there) then browser stops the request going to server. To enable server side validation only when client side form validation are not done, we can send one flag to server from client(form page) using hidden box javascript.