Announcement Announcement Module
No announcement yet.
weird problem with URL encoding on redirect. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • weird problem with URL encoding on redirect.

    I have a controller with 2 handler methods in it. One of the controllers creates a redirect like so

           UriComponents redirectUri = UriComponentsBuilder.fromPath("/shelflocation/view")
                .queryParam("shelfLocationId", shelfLocation.getId()).build().encode();
            return "redirect:"
                + redirectUri.toUriString();

    And the handler method I am calling looks like this:

        @RequestMapping(value = "/view", method = RequestMethod.GET)
        public ModelAndView view(@RequestParam(value = "shelfLocationId", required = true)
        final long id)
    Now I dont think there is any problem with the handler method because I call into that same view handler from a jsp via link like this:
    <a target="_blank" href="<c:url value="/shelfLocation/view?shelfLocationId='+shelfLocationId+'"/>">
    and that works fine.

    As a matter of fact I can copy and paste the link out of the browser address bar and into a new tab and it works in one case and in the other it does not. Yet to my eye they look identical.

    Here are the links:

    The below link is generated on the redirect and does not work. I cannot copy and paste this into a new browser tab and get in my handler method.

    The below link is generated from the href link in the jsp. It does work. I can copy and paste it into a new tab on my browser and get into my handler method.

    Has anyone ever experienced an issue like this before?


  • #2
    Damn I spent all morning on this. Apparently I had c+p some portion of the redirect String and something goofy happened in STS. What was there looked like what I pasted but apparently was not. Deleting the redirect:... portion and typing it out again fixed the problem.