【问题标题】:How to get PathVariable (String) in a Controller method如何在 Controller 方法中获取 PathVariable(字符串)
【发布时间】:2011-11-27 13:14:58
【问题描述】:
@RequestMapping(value = "/user/search/{email}")
    public String auditUseremail(@PathVariable("email") String email,Map<String, Object> map) {

        System.out.println(email);
}

这是我的控制器类函数,当action为http://localhost:8080/LACASServer/secure/user/search/user@cohaesus.co.uk时调用

你可以看到,电子邮件在 URL 中,但是当我用上述方法打印它时,我得到它user@cohaesus.co,谁能告诉我,可能是什么问题以及如何解决它。

【问题讨论】:

    标签: jsp spring-mvc path-variables


    【解决方案1】:

    我认为您应该对该路径使用 URL 编码,然后在控制器内部对其进行解码

    java.net.URLEncoder.encode(email, "ISO-8859-1");
    

    您可以阅读更多关于它的信息here

    【讨论】:

      猜你喜欢
      • 2016-09-22
      • 2019-09-27
      • 2012-02-23
      • 1970-01-01
      • 2014-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多