0

I have a JSP file which when loaded to the browser,displayed all the form fields,etc. I had written some wrong things like accessing a variable which is never defined and one more thing like writing a random string without any semicolon as well

The form gets loaded and the validation checks and all happen unless the code reaches that point.

After that the code exits and there is no error or exception message in the UI as well as the console.

I need to know how the compilation process happen in the first place it self if the code which i wrote in one of the validation function is not syntactically correct in java.

EDIT :-

The following is the code snippet with all the variables declared except the address variable:-

alert("Came before the if check");
if (firstName=="" || lastName=="" || address=="" || state=="null" || city=="" ||  amt=="" || prof=="" )
{
alert ( "Fields marked * are mandatory" );
document.registration.firstname.focus();
return false;
}
alert("came after address");
if (contact==""||contact.length<10||contact.length>10)  
{
alert ( "Please enter 10 digit contact no." );
document.registration.mobileNo.focus();
  return false;
}

So the first alert comes and the code never reaches the next alert which was needed to validate the contact field in the form

If I change the field to "add" instead of "address" which is defined before,then both the alerts are displayed along with the validation being done.

  • 1
    Post your code. And stop writing Java code in JSPs in the first place. http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files – JB Nizet Apr 23 '16 at 07:25
  • Have added the code snippet now. :) – Prateek Jain Apr 23 '16 at 08:55
  • That is not Java code. It's JavaScript code. So it's never compiled at server-side. For the JSP container, that's just text that must be sent to the browser. The browser executes that code. Java is to JavaScript what a car is to a carpet. – JB Nizet Apr 23 '16 at 20:30
  • But how much I have learnt,the first step in the JSP life cycle is compilation.It is this compilation that the JSP is then turned to a servlet.Please let me know where I am going wrong here. – Prateek Jain Apr 25 '16 at 09:40
  • JSP contains text that must be sent to the browser, custom JSP tags, and scriptlets containing Java code. The JSP is compiled into a servlet that contains the scriptlet code, invokes the custom tags, and sends the text to the browser. The code you have posted is JavaScript code. For the JSP, it's just text that must be sent to the browser. It would be compiled if it was Java code contained in a scriptlet. But it's not Java code, and it's not contained into a scriptlet, so it's just text. – JB Nizet Apr 25 '16 at 09:57
  • Thanks for explaining that..Could you please say what is scriptlet code then because the code which i have given here is in between the – Prateek Jain Apr 26 '16 at 11:40
  • – JB Nizet Apr 26 '16 at 16:36
  • I understood...I got confused. Really thanks for solving my confusion. – Prateek Jain Apr 27 '16 at 10:55

0 Answers0