Manas Saxena wrote: since my ajax call simply prints the apt message.
That's your problem. You're just returning semantic-less text and shoving it into the DOM. Not a good approach,
Rather, submit the Ajax to a
servlet (never, ever, ever, ever use a JSP for processing) that returns JSON data (which could be as simple as true or false, or as complex as you like). JavaScript can then set an error message, set a class on the form field that indicates it is error, or do anything else that needs doing.
Relying on JSP for this is a grave mistake.