0

I am very new to JAVA Servlets so pardon me if the question sounds silly. Basically, I have simple static HTML page having a form with input fields accepting values from a user. When a user enters values and click submit button values are sent to JAVA servlet where it does validation for values. If validation is failed I want servlets to send the old values which are correctly entered in addition to an error message for the invalid field and this will be displayed in static HTML page. How can I accomplish this with static HTML page and Java servlet?

I understand and totally agree that JSP would make my life easier in such case. However, if I have to use only HTML static page and JAVA servlet what are the options available?

1 Answers1

0

You can include Javascript in the static web page that is called by the submit button onclick event and makes an AJAX call to the servlet. The servlet should respond with JSON or XML containing the validation results/error message. The form fields and/or error message text can be updated in the response handler Javascript function.

There are several examples on StackOverflow including this one. Scroll down to "Ajaxifying an existing form".

Community
  • 1
  • 1