URISyntaxException 查询中的非法字符 [英] URISyntaxException Illegal character in query

查看:30
本文介绍了URISyntaxException 查询中的非法字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在默认浏览器中打开链接.我使用了以下代码.

I am trying to open a link in default browser. I have used the following code.

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 非法字符

I am getting URISyntaxException Illegal character in query at index

我认为这是因为我的 URL 中的 ?&! 等字符造成的.我尝试使用:

I think this is because of characters such as ?, & and ! in my URL. I tried using:

URLEncoder.encode(myUrl, "UTF-8");

但这给了我另一个错误.

But this gives me another error.

Failed to open http%3A%2F%2Fwww.example.com%2F........... 
The system cannot find the file specified.

请告诉我如何更正URISyntaxException Illegal character 错误.

Please can you tell me how to correct the URISyntaxException Illegal character error.

推荐答案

是因为这里有空格 ...jsp?Type=A Type&...,可以换成 <代码>+

It's because of the whitespace here ...jsp?Type=A Type&..., you can replace it with +

http://www.example.com/engine/myProcessor.jsp?Type=A+Type&Name=1100110&Char=!"

这篇关于URISyntaxException 查询中的非法字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆