Posts

Showing posts with the label MVC

#4 Working with Spring MVC

Image
MVC stands for Model-View-Controller. MVC in spring required: Some JSP pages ( views) which need to be displayed. Controller which used to access views Model to set for views So lets start with MVC. Before starting I hope you have idea of basic REST api development. If not then you can follow steps here . For MVC, we need to follow steps below: 1. Create a ModelController class. Add annotation  @Controller on top ( with @RestController it will not work). 2. Create JSP page, let say index.jsp . Please check hierarchy in folder structure for index . jsp page as we will require to tell our application that from where JSP pages need to pick. 3. Create HelloConfig.java  to register InternalResourceViewResolver .  InternalResourceViewResolver  is used at application level to tell application path of JSP/CSS files. I have set path to "/WEB-INF/pages" and added suffix as .jsp . So now I won't require to specify .jsp expli...

#5 Passing argument in Spring MVC

Image
This tutorial is next step of my previous tutorial . In this tutorial we will simply create: One login form. One success page One failure page Controller for redirection 1. Lets start with Login form as given below: Please note that in form I have defined action as login_authenticate . This will be the REST api name which we will require to develop. Once login will press it will search for  login_authenticate api. 2. Create Error page as below: 3.Create Welcome page as below: Please note that I have used ${name} . It will pick value set via ModelMap ( see login_authenticate api below in blog.) 4. Create  login  api in ModelController to display login page: 5. Now create  login_authenticate api which will be called for authentication. Please note that in below api we added some constant username/password for authentication. You can use your Db for the same: In above api I just read value of JSP email and...