In Java webapp, I need an automatic converter to convert String to use in a mailto link
By example, I have this String “S&D” will be display in a html correctly “S&D”. But now I need to have a mailto link in my web page.
<a href="mailto:?subject=my%20subject&body=S&D">share</a>
its wrong character “&”, so I need to convert “&” to “%26”.
There is a library to do that?
I tried java.net.URLEncoder but she changed only the “&” not the “&” and she replace space ” ” by plus “+”
I tried java.net.URI but she did nothing for character “&”!
Quoting RFC 6068(thanks JB Nizet):
Updated code:
Output:
Which may be used in a link like so:
StringEscapeUtils.escapeHtml(String str) from Apache Commons Lang.