Results 1 to 3 of 3

Thread: Obtaining @PathVariable in an interceptor

  1. #1
    Join Date
    Jan 2012
    Posts
    4

    Default Obtaining @PathVariable in an interceptor

    Hi

    We're using an interceptor to some of our controllers to check that the user is logged on.

    The controller method has a path variable in the signature....

    Code:
    @RequestMapping(method=RequestMethod.GET)
    public String getVehicleForListing(@PathVariable String listingId, Model model) {
    .....
    }
    Is there an easy way to extract that @PathVariable in the interceptor method...


    Code:
    public boolean preHandle(HttpServletRequest request,  HttpServletResponse response, Object handler)
    	    throws Exception {
    ......
    }
    I wondered whether there is any spring component that I could inject into the interceptor to extract that path variable.

    Thanks for all help

    tc

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,632

    Default

    Nope... The pathvariable is available after the prehandle method. It is produced by the RequestMappingHandlerAdapter and that is only called after succesful invocation of the preHandle methods of all interceptors.

    Also why would you need to attribute if it is a pathvariable it is part of your url, so storing the url and redirecting after successful login should be enough. Also I suggest using Spring Security instead of implementing your own solutions...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jul 2011
    Location
    Singapore
    Posts
    2

    Default

    Map pathVariables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_V ARIABLES_ATTRIBUTE);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •