Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java邮件中的URL编码_Java_Url_Encoding - Fatal编程技术网

Java邮件中的URL编码

Java邮件中的URL编码,java,url,encoding,Java,Url,Encoding,我用java编写了一段代码,其中有表单(输入字段),最后在底部有一个发送电子邮件按钮。当用户单击按钮时,输入字段中的数据应被提取出来,然后用作电子邮件中正文的数据 这是我的代码: if (role.getValue().equals("1")) { Desktop desktop = Desktop.getDesktop(); String message = "mailto:username@domain.com?subject=Profildaten&am

我用java编写了一段代码,其中有表单(输入字段),最后在底部有一个发送电子邮件按钮。当用户单击按钮时,输入字段中的数据应被提取出来,然后用作电子邮件中正文的数据

这是我的代码:

if (role.getValue().equals("1")) {          
    Desktop desktop = Desktop.getDesktop();
    String message = "mailto:username@domain.com?subject=Profildaten&body=" +
                     "Externe%20Referenz:%20" +
                     person.getExternalReference() + "%20" + "-%20" +
                     person.getExternalReferenceType() + "%0A" +
                     person.getTitle() + "%20" +
                     person.getContactLandline() + "%0A" +
                     "Mobil:%20" + person.getContactMobile() + "%0A" +
                     "Addresse:" + person.getContactStreet();

    URI uri = URI.create(message); 
    try {
        desktop.mail(uri);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }   
}

这一切都很完美,但唯一的问题是地址:person.getContactStreet()实际输入字段要求用户输入街道名称,通常是两个单词,例如克伦威尔路,在克伦威尔和路之间有一个空格。现在,电子邮件正文不允许有空格和其他无效字符,因此它会弹出一条错误消息,说输入了无效字符。我怎样才能让它接受这一点或将无效字符自动转换为url编码?

看看这个网站,它告诉你如何自动编码正文中的url


看看这个网站,它告诉你如何自动编码正文中的URL


我不太清楚怎么做,因为。论坛上确实说,我可以用+或%20替换空间。但是,如果用户手动将数据输入到字段中,我无法让他这样做。用户通常会用空格输入数据,但程序不会接受。有什么办法?使用Pita Sivam提供的链接详细信息,您可以对用户在服务器端输入的数据进行编码,而不必强制用户以编码形式输入数据。@Logan-是的,我看到了链接,但这是一个URL编码器。有没有像字符串编码器这样的东西,这样用户的输入就可以自动编码?@Priya基本上URL编码器做的就是编码一个字符串,因为底部的URL只是一个字符串。我不太清楚怎么做,因为。论坛上确实说,我可以用+或%20替换空间。但是,如果用户手动将数据输入到字段中,我无法让他这样做。用户通常会用空格输入数据,但程序不会接受。有什么办法?使用Pita Sivam提供的链接详细信息,您可以对用户在服务器端输入的数据进行编码,而不必强制用户以编码形式输入数据。@Logan-是的,我看到了链接,但这是一个URL编码器。有没有像字符串编码器这样的东西,以便用户的输入自动编码?@Priya基本上URL编码器所做的就是编码字符串,因为底部的URL只是一个字符串。