@InitBinder annotation, WebDataBinder, CustomDateEditor

In our previous article we have seen that once Spring fails to bind the data type because of mismatch,the controller redirects the request to the RegistrationForm.jsp with error message. What if we want to retain those values of the Student object except the one for which user has entered incorrect…

Continue reading

Data Binding with Date, Collection (Arraylist), Long

We will continue with the same example to understand some more advance feature of data binding. To understand this we will edit our Student.java,RegistrationForm.jsp and RegistrationSuceess.jsp We are adding some some more parameter to our Student class along with their getters and setters which are private Long StudentCellNumber; private Date…

Continue reading

@ModelAttribute Annotation -part 2

In this article we will see use of @ModelAttribute at Method level @ModelAttribute at Method level Now if you have notice that we are using the same model object in different request handler method (getRegistationForm and submitRegistrationForm) of  same Controller class. Now in our example if you have notice we…

Continue reading

@ModelAttribute Annotation -part 1

@ModelAttribute Annotation The @ModelAttribute Annotation can be used at two levels in a Controller class At Method argument level At Method level Lets us first see how @ModelAttribute Annotation is used at method argument level and how we can achieve more by writing less code. We will continue with the same example…

Continue reading

Handling an HTML form using @RequestParam annotation

Handling an HTML form using @RequestParam annotation Lets understand this with help of a Registration page,where user will enter the input in the front end and then we will capture it in the controller class and then process the request. Files and changes Required : StudentRegistrationController.java RegistrationForm.jsp RegistrationSuccess.jsp Add the…

Continue reading

@PathVariable annotation in Spring MVC

@PathVariable annotation Now Suppose in the same sample application if the  @RequestMapping(“/welcome/country/UserName”)  is the url pattern and the User enters http://localhost:8080/SpringMVC/welcome/country/UserName He will see below as the output, Now suppose we replace the hardcoded UserName in the url with the value such as http://localhost:8080/SpringMVC/welcome/country/Shailesh and the application will not be…

Continue reading

MultiAction Controller class, @RequestMapping annotation at class level

MultiAction Controller class: In Spring Framework ,you can write as multiple request handler method in one controller class like below: @Controller public class HelloController { public HelloController() { } @RequestMapping(“/welcome”) public ModelAndView helloWorld() { ModelAndView modelandview = new ModelAndView(“HelloPage”); modelandview.addObject(“msg”, “Hello World”); return modelandview; } @RequestMapping(“/hi”) public ModelAndView hi() {…

Continue reading

First MVC using Annotation

Using the same project which we have used in the previous post,we will see what changes are required in case if we are using annotation Below are the changes that we need to make ; 1>We need to comment the entries for the handler mapping and controller class in spring-dispatcher-servlet.xml <!–…

Continue reading

First MVC Application

We need to follow these steps: Modify web.xml file Create Spring Dispatcher Servelet Create the HelloController.java class( which acts as controller) Create the HelloPage.jsp we need to add this code in our web.xml file <servlet> <servlet-name>spring-dispatcher</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>spring-dispatcher</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> ———————— In DispatcherServlet we have to…

Continue reading