我想在使用Java发送的HTML电子邮件的电子邮件正文中显示特殊的字符或符号。下面是问题的细节。
我已经创建了一个扩展,它获取网页中输入的所有文本框,我将这个文本存储在字符串变量中,并将该变量作为参数传递给负责发送电子邮件的方法。如果用户将"←“这样的特殊字符或符号放在文本框中,则在电子邮件正文中显示为”†“,我如何使用java处理这些特殊字符或符号,使其显示在电子邮件正文中。
下面是我的代码
String description = "Here I am getting all text from Text box in webpage, it can also
contain special character as explained above";
String emailSubject = "test HTML email";
String emailBody = "<!DOCTYPE html>" + "<html>" + "<body>" +
"<p>Please review this work item and assign it to the appropriate owner.</p>" + description+
"</body>" + "</html>";
//below is the method responsible for sending email to which I pass string parameters emailSubject
//and emailBody 发布于 2018-10-31 13:58:19
您可以用HTML实体表示特殊符号。您基本上需要将符号映射到HTML实体并在字符串中替换它们。例如,用户输入可以用←替换的箭头符号,并将以←的形式显示在HTML中。
您可以使用这个类为您执行此操作:https://commons.apache.org/proper/commons-text/apidocs/org/apache/commons/text/StringEscapeUtils.html
发布于 2018-10-31 13:55:55
在html head部分中添加以下内容:
<meta http-equiv="content-type" content="text/html;charset=utf-8" />https://stackoverflow.com/questions/53084912
复制相似问题