gpt4 book ai didi

java - 无法在 groovy 中导入 java.net.URLEncoder

转载 作者:太空宇宙 更新时间:2023-11-04 14:48:47 26 4
gpt4 key购买 nike

我对 groovy 还很陌生,正在尝试在我的第一段 groovy 代码中编码 URL。

这是我的代码的一部分:

import java.net.URLEncoder
String url = baseUrl + URLEncoder.encode(parameter);

它看起来与我在网上查看的许多示例完全相同,但它会抛出如下错误。

General error during canonicalization: Importing [java.net.URLEncoder] is not allowed

java.lang.SecurityException: Importing [java.net.URLEncoder] is not allowed

我还尝试直接使用该类,如图所示here

String url = baseUrl + java.net.URLEncoder.encode(parameter);

另一个版本:

String url = baseUrl + URLEncoder.encode(parameter);

都抛出错误:

General error during canonicalization: Indirect import checks prevents usage of expression

java.lang.SecurityException: Indirect import checks prevents usage of expression

感谢任何大师可以帮助消除疑虑。

最佳答案

根据http://groovy.codehaus.org/Differences+from+Java默认情况下会导入 Groovy 中的 java.net.* 包,这意味着 java.net.URLEncoder 也会被导入。无需导入即可使用。

编辑:对我来说,使用这个 Groovy 代码:

println URLEncoder.encode("URL encoding fine!")

打印URL+encoding+fine%21

关于java - 无法在 groovy 中导入 java.net.URLEncoder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24055159/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com