Simple Form Controller Example

How much time will it take to learn Spring and Hibernate? Simple Spring Boot Example Spring Boot Console Application Spring Boot Tutorials Advantages of Spring Framework Spring 4 Introduction and example Features of Spring Framework 5 How to make Spring web Login form? How to make Simple form in Spring web? Spring, Hibernate login and registration application Spring Framework Tutorial for beginners with examples Spring Framework for Apache Hadoop 2.3.0 GA released Spring Framework 4.1 GA is released with major features Why to use Spring Framework? Spring Framework 4.1 - First Release candidate available Spring IO Platform 1.0.0 Released Spring 4: Login Form using Spring MVC and Hibernate Example Spring 4 MVC Login form Example with source code Spring 4 MVC Hello World Example: Spring 4 MVC Tutorial will full source code Spring Web MVC Application Error:ClassNotFoundException: DispatcherServlet on deploying Features of Spring 4 Spring Framework 4.0 released Spring Framework 4: Spring Framework 4 Tutorials and Example Spring Integration 3.0 Release is released and available for download Spring Tutorial for Beginners Java Springs Framework Tutorial Spring Architecture Spring Framework Tutorials database spring registration form Spring Login Example Roseindia Spring Tutorial Spring Tutorial Spring 3.2 MVC insert and retrieve blob from the database The hidden tag The errors tag net.roseindia.dao net.roseindia.service net.roseindia.model net.roseindia.controller Spring 3.2 MVC Hibernate Example

Simple Form Controller Example

Example of using Simple Form Controller.

Example of using Simple Form Controller.

Example of using Simple Form Controller

Page 2

In this page we will see the next steps necessary to run the example code. 

Here are the steps you should follow now. 

If you want to view the previous page check it at Example of using Simple Form Controller

Step 7:

Now we will create a class inside the project src folder to validate the wrong data entry in the user.jsp form fields by the user. The code of the class is:

package net.roseindia.web;
import java.util.regex.*;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import net.roseindia.web.User;

public class UserValidator implements Validator {

  public boolean supports(Class clazz) {
  return User.class.isAssignableFrom(clazz);
  public void validate(Object obj, Errors errors) {
  User user = (User) obj; 

  if ((user.getEmailid() != "") || 
(user.getEmailid().length()) != 
0) {
  Pattern p=Pattern.compile("[email protected]+\\.[a-z]+");

          Matcher m=p.matcher(user.getEmailid());
          boolean b=m.matches();

"""Email ID does not Valid ");        
      if ((user.getContact() != "") ||

 (user.getContact().length()) != 0) {        
          Pattern pattern = Pattern.compile

          Matcher matcher = pattern.matcher

          boolean con=matcher.matches();


"Enter Contact Number Like 0-9999-999999");
      if ((user.getDob() != "") || (

user.getDob().length()) != 0) {        
      Pattern pattern = Pattern.compile

      Matcher matcher = pattern.matcher(user.getDob());
      boolean DOB=matcher.matches();

"""Enter Date of birth Like 01/02/1986 ");
      if (user.getName() == null || 

user.getName().length() == 0) {

"error.empty.field""Please Enter Name");
        if (user.getDob() == null || 

user.getDob().length() == 0) {

"error.empty.field""Please Enter Date Of Birth");
        if (user.getContact() == null || 

user.getContact().length() == 0) {

 "error.empty.field""Please Enter Contact Number");
        if (user.getEmailid() == null || 

user.getEmailid().length() == 0) {

 "error.empty.field""Please Enter Email ID");
        if (user.getQualification() == null ||

 user.getQualification().length() == 0) {

 "error.empty.field""Please Enter Qualification");
        if (user.getAddress() == null ||

 user.getAddress().length() == 0) {

"error.empty.field""Please Enter Address");

Step 8:

Now we will run this example and see the output like:

After  click on this link user can see the form to enter user personal details like:

If user enter wrong data then validator call by the controller and display errors like:

If user fill correct data then output like:

Download Code

Download this example code