How to read request parameter values Using HandlerInterceptor in spring?

I'm using HandlerInterceptor to trigger all the events/actions happens in my applications and save it to audit table. In table I'm saving the information like servername, session, parameters etc..

So using HandlerInterceptor how can I read all those parameters values and the pathvariable values what I'm passing in my controller.

Here is my code :

    public class AuditInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {
            LOG.debug("URL path"+request.getRequestURI());
                return true;
    }

    @Override
    public void postHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler,
            ModelAndView modelAndView) throws Exception {
        LOG.debug("URL PATH :"+request.getRequestURI());

    } 

}

My controller class enter code here::

public class ABCDController {
@RequestMapping(value="categories",method=RequestMethod.GET)
    @ResponseBody
    public List<Category> getCategoryList(@RequestParam String divisions){
        return service.getCategoryList(divisions);
    }
}

So how can I read the parameter name and values using HandlerInterceptor's HttpServletRequest request object.

Answers


The Servlet API provides a way to read the Request Parameters. For example,

ServletRequest.getParameterMap() returns a map of key-values of the request parameters.

However, for Path variables and values, I don't know if Spring MVC offers a simplified way of doing it, but using Servlet API again, you can read the URI using HttpServletRequest.getRequestURI(). You'll have to have your own logic to split it up into appropriate Path parameters.


Need Your Help

SEO Question - HTTP versus HTTPS?

seo

When getting indexed by search engines, is there a difference if the public side of a site is served via HTTPS or via HTTP?

Bootstrap : Carousel images are not moving

css html5 twitter-bootstrap css3 carousel

Hey i am trying to implement carousel on page. but issue I am facing is only active image is showing on screen. images are even not moving ie the second and third image is not showing despite beign