Access HttpServletRequest and HttpServletResponse in Spring MVC controller

In some cases, you will need to access the HttpServletRequest and HttpServletResponse objects in the Spring MVC controller when processing a request URL. At that point, you need to simply add two variables referencing these two objects as parameters of the method.

In the example of the previous tutorial, we can add two more arguments to the home() method and log some information like this:

At this point, Spring MVC will automatically put these two objects into our method and thus you can access all the properties of these two objects.


Chia sẽ bài viết này ...Share on Facebook
0Tweet about this on Twitter
Share on LinkedIn

Add Comment