Hello,
I am writing this post to share a problem I encountered and the solution that I used to fix it.
I make use of the httpServletResponse.sendRedirect() method quite often for one of my projects, as it allows me to reuse the same view logic for multiple URLs. Redirecting works perfectly for English characters, however it does not work properly for Unicode characters.
This is where I encountered the issue!
return "redirect:/list/blog/author/" + author + "/1";
HTTP request headers provide support for a range of characters as mentioned below.
- Alphanumeric characters: a-z, A-Z, 0-9
- Special characters: _ :;.,/”‘?!(){}[]@<>=-+*#$&`|~^%
The author may include both ASCII and Unicode characters, which is why the redirection method fails when Unicode characters are passed to the author variable. To avoid this issue, we should encode the characters before passing them to the redirection method.
return "redirect:/list/blog/author/" + UriUtils.encode(author, "UTF-8") + "/1";
Success! It finally works!
Related links:
Google bard: https://g.co/bard/share/7ed197a9a570