【发布时间】:2019-02-18 09:37:28
【问题描述】:
我有一个 Primefaces Commandlink,它在我的 mailto 地址末尾提供了一个工件。我不确定“#”是从哪里来的。
这是前端代码。
<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 编码的空格“+”。
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();
}
【问题讨论】:
-
所以如果你使用
p:commandLink和 ajax 你没有这个吗?还是没有ajax?还是来自没有 jsf 的单元测试? -
对于 ajax="true" 和 ajax="false",'#' 字符仍然存在。
-
抱歉,应该是
h:commandLink;-) 排除它与 PF 相关 -
并且请在单元测试中尝试 99,9% 肯定与 jsf 或 primefaces 无关
标签: java primefaces jsf-2