gpt4 book ai didi

java - 桌面和 URI 生成角色工件

转载 作者:行者123 更新时间:2023-12-02 10:49:05 25 4
gpt4 key购买 nike

我有一个 Primefaces Commandlink,它在我的 mailto 地址末尾提供了一个工件。我不确定“#”来自哪里。

enter image description here

这是前端代码。

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

这是后端操作代码。

    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();
}
}

[编辑]

我可以去掉“#”,但随后会得到 UTF-8 编码的空格“+”。

enter image description here

        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();
}

最佳答案

哈希字符由您正在使用的构造函数附加。看看JavaDoc :

public URI(String scheme, String ssp, String fragment) throws URISyntaxException

[...]

Finally, if a fragment is given then a hash character ('#') is appended to the string, followed by the fragment. Any character that is not a legal URI character is quoted.

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

关于java - 桌面和 URI 生成角色工件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52317302/

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