we will learn Spring MVC Form handling without using database. Here, we will use @Controler, @RequestMapping and @ModelAttribute annotations.

To display the input form, we are going to use <form:form> tag of spring framework. Let’s see a simple example to store form data in a model object and display data of a list.

Following is the content of Student.java file.


Following is the content of StudentController.java file.


Here the first service method showform(), we have passed a blank Student object in the ModelAndView object with the name “command” because the Spring framework expects an object with the name “command” if you are using tags in your JSP file. So, when showform() method is called , it returns studentform.jsp view.

The second service method save() will be called against a POST method on the MVCFormExample/studentform URL. You will prepare your model object based on the submitted information. Finally a result view will be returned from the service method viewstudent(), which will result in rendering viewstudent.jsp.

Following is the content of Spring Web configuration file web.xml.


Following is the content of another Spring Web configuration file spring-servlet.xml


Following is the content of index.jsp file.


Following is the content of studentform.jsp file.


Following is the content of viewstudent.jsp file.



Leave a Reply

Your email address will not be published. Required fields are marked *