我试图在默认浏览器中打开一个链接。我使用了以下代码。
String myUrl = "http://www.example.com/engine/myProcessor.jsp?Type=A Type&Name=1100110&Char=!";
try {
Desktop.getDesktop().browse(new URI(myUrl));
} catch (IOException err) {
setTxtOutput("Error: "+err.getMessage());
} catch (URISyntaxException err) {
setTxtOutput("Error: "+err.getMessage());
} catch (Exception err) {
setTxtOutput("Error: "+err.getMessage());
}
我在索引查询中得到 URISyntaxException Illegal character
我认为这是因为诸如 ? , & 和 ! 在我的网址中。我尝试使用:
URLEncoder.encode(myUrl, "UTF-8");
但这给了我另一个错误。
Failed to open http%3A%2F%2Fwww.example.com%2F...........
The system cannot find the file specified.
请告诉我如何更正 URISyntaxException 非法字符 错误。
原文由 Harshit Gupta 发布,翻译遵循 CC BY-SA 4.0 许可协议
这是因为这里有空格
...jsp?Type=A Type&...
,你可以用+
代替