当 url 中包含外语字符 (تشكيل) 时,Spring 应用程序不会重定向
我有一个 Spring 应用程序,它工作正常,除了它如何处理控制器重定向用户时需要包含在重定向 url 中的外语字符。
例如,如果控制器将用户重定向到以下 URL,则会失败:
http://localhost:8080/diacritic/تشكيل
I have a Spring app that is working correctly except for how it deals with foreign language characters that need to be included in the redirect url when the controller redirects the user.
If the controller redirects the user to the following URL, for example, it will fail:
http://localhost:8080/diacritic/تشكيل
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要重新编码重定向目标。
我有这样的代码:
这对我有用。
You need to re-encode the redirection target.
I have code like this:
This worked for me.
路径变量在 ISO-8859-1 中解码。您可以采取两件事来解决这个问题。
要查看服务器上实际的 UTF-8 解码字符,您可以执行此操作并查看该值(您需要将“HttpServletRequest httpServletRequest”添加到控制器参数中):
既然服务器上已经有了正确的数据,那么您就可以做任何您想做的事情了。
您还可以尝试向 web.xml 文件添加过滤器。
The path variable is decoded in ISO-8859-1. There are two things you can do to get around this.
To see the actual UTF-8 decoded characters on the server, you can just do this and take a look at the value (you need to add "HttpServletRequest httpServletRequest" to your controller parameters):
You can then do whatever you want, now that you have the right data on the server.
You can also try adding a filter to your web.xml file.