Spring MVC 3.1 - How to Get HttpServletRequest and HttpServletResponse objects in Controller Method

When Spring MVC 3.1 dispatcher introspect the parameters lists of user defined controller method that is to be executed. It identifies it from URL pattern. Using reflections it introspect the types of parameters and pass the required object to that controller method. For example, there is a method hello() which expect HttpServletRequest and HttpServletResponse object binded or associated with current under-process request, the hello() method can be declared like this:

public class HelloController {

@RequestMapping(method = RequestMethod.GET)
public String hello(HttpServletRequest request, HttpServletResponse response) {

// Use request and response object as you in JSP or Servlets


So, the Spring MVC 3.1 would automatically pass the defined parameters.


Popular posts from this blog

Task 12 - Create Java Program with MySQL Database Connectivity

Java Interfaces and Exception Handling - Practice Problem with Solution

Task 16 - Javafx Program to Create, Retrieve, Update and Delete records with Database