Spring MVC Model InterfaceIn Spring MVC, the model works a container that contains the data of the application. Here, a data can be in any form such as objects, strings, information from the database, etc. It is required to place the Model interface in the controller part of the application. The object of HttpServletRequest reads the information provided by the user and pass it to the Model interface. Now, a view page easily accesses the data from the model part. Methods of Model Interface
Spring MVC Model ExampleLet's create a login page that contains a username and password. Here, we validate the password with a specific value. 1. Add dependencies to pom.xml2. Create the request pageHere, we create the login page to receive name and password from the user. index.jsp 3. Create the controller classIn controller class:
HelloController.java 4. Provide the entry of controller in the web.xml fileweb.xml 5. Define the bean in the xml filespring-servlet.xml 6. Create the other view componentsTo run this example, the following view components must be located inside the WEB-INF/jsp directory. viewpage.jsp errorpage.jsp Output: Next TopicRequestParam Annotation |