【问题标题】:How to handle GET request mounted with axios with specials caracters and accents如何处理带有特殊字符和重音符号的 axios 的 GET 请求
【发布时间】:2020-12-17 03:14:43
【问题描述】:

在使用 VUE.JS 构建的网页形式中,使用 Axios 挂载 GET 请求。

并且根据某些表单字段的值,可能会有特殊字符和重音符号。

例如,如果在 surname 表单字段中,用户写 'Ruíz',则请求是这样挂载的:

http://localhost:9000/someController?surname=Ru%C3%ADz

似乎'í'被转换为%C3%AD

这是我在 Java 方面的控制器:

@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public SignerQueryResponse getSignerList(
    @RequestParam(value = "surname", required = false) String surname,
    HttpServletRequest request) {

    //... all stuff

}

如何纠正?

我必须在服务器端放一些东西吗? .. 在 Java 控制器中??

...与 ISO-8859-1 编码有关的东西??

谢谢

【问题讨论】:

  • 您需要在服务器上使用decodeURIComponent('Ru%C3%ADz')进行转换。
  • This 应该有帮助
  • 谢谢你们的cmets

标签: java spring-boot vue.js http axios


【解决方案1】:

我找到了一个解决方案,使用 org.apache.commons.lang.StringEscapeUtils.unescapeHtml()

但我不知道是否存在另一个更“清洁”,例如基于@annotations。

System.out.println(surname); //This gives me unproper: Ruíz
                
String unescapedSurname = StringEscapeUtils.unescapeHtml(surname);
System.out.println(unescapedSurname); //This gives me the proper: Ruíz

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-24
    • 2011-10-29
    • 1970-01-01
    • 1970-01-01
    • 2013-07-14
    • 2023-03-03
    • 1970-01-01
    相关资源
    最近更新 更多