Java 桌面和URI生成字符工件

Java 桌面和URI生成字符工件,java,primefaces,jsf-2,Java,Primefaces,Jsf 2,我有一个Primefaces命令链接,它在我的mailto地址的末尾给了我一个工件。我不知道“#”是从哪里来的 这是前端代码 <p:commandLink value="Mail Video Link" action="#{requestBean.requestUtility.informationRequestLink()}" /> [编辑] 我可以去掉“#”,但是我得到了UTF-8编码的空格“+” 哈希字符由正在使用的构造函数追加。 请看一下: public UR

我有一个Primefaces命令链接,它在我的mailto地址的末尾给了我一个工件。我不知道“#”是从哪里来的

这是前端代码

<p:commandLink value="Mail Video Link" action="#{requestBean.requestUtility.informationRequestLink()}" />     
[编辑]

我可以去掉“#”,但是我得到了UTF-8编码的空格“+”


哈希字符由正在使用的构造函数追加。 请看一下:

public URI(字符串方案、字符串ssp、字符串片段)抛出URISyntaxException

[……]

最后,如果给定了一个片段,则会在字符串后面附加一个哈希字符(“#”),后跟片段。任何不是合法URI字符的字符都会被引用


您应该使用适当的
URI构造函数
;请参阅文档。在我看来,你的第三个参数更像是一个
查询
而不是一个
片段

,所以如果你在ajax中使用
p:commandLink
,你没有这个吗?还是没有ajax?或者从没有jsf的单元测试中?对于ajax=“true”和ajax=“false”,仍然存在“#”字符。对不起,应该是
h:commandLink
;-)要排除它,请在单元测试中尝试99,9%确定不是jsf或primefaces Related更新构造函数以正确使用它。原始构造函数=URI mailURI=新URI(“mailto”user@domain.com“,mailURIString);新构造函数=URI mailURI=新URI(“mailto”,mailustring,”);答对 了
    public void informationRequestLink() {
    String subject = "Video Link";
    String cc = "friend2@domain.com,friend3@domain.com";
    String requestLink = "https://www.youtube.com/watch?v=SjeS6gtPq8E";
    String body
            = "Here is the link.\n"
            + requestLink + "\n\n"
            + "Watch at your leisure.";

    try {
        Desktop desktop = Desktop.getDesktop();

        String mailURIString = String.format("?subject=%s&cc=%s&body=%s",
            subject, cc, body);
        URI mailURI = new URI("mailto", "user@domain.com", mailURIString);

        desktop.mail(mailURI);
    } catch (IOException | URISyntaxException e) {
        e.printStackTrace();
    }   
}
        String subject = "Video Link";
    String cc = "friend2@domain.com,friend3@domain.com";
    String requestLink = "https://www.youtube.com/watch?v=SjeS6gtPq8E";
    String body
            = "Here is the link.\n"
            + requestLink + "\n\n"
            + "Watch at your leisure.";

    try {
        Desktop desktop = Desktop.getDesktop();

        String mailURIString = String.format("mailto:%s?subject=%s&cc=%s&body=%s",
                "friend1@domain.com", subject.replaceAll(" ", "%20"), cc, URLEncoder.encode(body, "UTF-8"));
        URI mailURI = URI.create(mailURIString);

        desktop.mail(mailURI);
    } catch (Exception e) {
        e.printStackTrace();
    }