Spring Controller:将Url作为参数404错误传递

时间:2014-07-14 01:38:15

标签: java spring model-view-controller

我的控制器在字符串的末尾附加一个问号。它适用于各种类型的字符串。

https://www.mywebsite.com/attachQuestionmark/33 returns 33?
https://www.mywebsite.com/attachQuestionmark/hello returns hello?

然而,对于诸如https :: //www.test.com之类的网址,它返回未找到的错误。

https://www.mywebsite.com/attachQuestionmark/https:://www.test.com返回404错误。

有没有办法将完整的url传递给spring mvc控制器?

@RequestMapping(
            value = MyUrlBuilder.API_CREATIVE_CREATE + "/attachQuestionmark/{string}",
            method = RequestMethod.GET,
            produces = MediaType.ALL_VALUE)
    @ResponseBody
    @PMET
    public static String attachQustionmark(@PathVariable("url") String value)
    {
        return value + "?";
    }

1 个答案:

答案 0 :(得分:2)

尝试URL-encoding路径变量,例如:

https://www.mywebsite.com/attachQuestionmark/https%3A%3A%2F%2Fwww.test.com

因为否则变量中的/将被解释为另一个路径