Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Spring MVC @PathVariable getting truncated

    • 0
    • 2
    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 2.30k
    Comment on it

    We generally face a problem when we hit server with path variable that contains special character like dot(.) it gets truncated.

    For Example: If you have the mapping

    @RequestMapping(value = "/findMe/{emailId}", method = RequestMethod.GET)
        public ModelAndView findMe(HttpServletRequest request,
                HttpServletResponse response,@PathVariable String emailId)
        {
    }
    

    and you make the request to /findMe/user@gmail.com then you will get email = "user@gmail" and .com will not get displayed (Spring treats them as file extensions and removes them for you.).

    Then to fix this issues you just need to provide regular expression for the @RequestMapping argument with the path variable as below:

    @RequestMapping(value = "/findMe/{emailId:.+}", method = RequestMethod.GET)
        public ModelAndView findMe(HttpServletRequest request,
                HttpServletResponse response,@PathVariable String emailId)
        {
    }
    

    Then for /findMe/user@gmail.com you will get email = "user@gmail.com"

    Hope this will help you :)

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: