Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6471677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:15:08+00:00 2026-05-25T06:15:08+00:00

In Java webapp, I need an automatic converter to convert String to use in

  • 0

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&amp;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 “&”!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:15:09+00:00Added an answer on May 25, 2026 at 6:15 am

    Quoting RFC 6068(thanks JB Nizet):

    When producing ‘mailto’ URIs, all spaces SHOULD be encoded as
    %20, and ‘+’ characters MAY be encoded as %2B. Please note that ‘+’
    characters are frequently used as part of an email address to
    indicate a subaddress, as for example in <bill+ietf@example.org>.

    Updated code:

    String subject = URLEncoder.encode("my subject", "utf-8").replace("+", "%20");
    String body = URLEncoder.encode("S&D", "utf-8").replace("+", "%20");
    // Email addresses may contain + chars
    String email = "test@example.com".replace("+", "%2B");
    String link = String.format("mailto:%s?subject=%s&body=%s", email, subject, body);
    System.out.println(StringEscapeUtils.escapeHtml(link));
    

    Output:

    mailto:test@example.com?subject=my%20subject&amp;body=S%26D
    

    Which may be used in a link like so:

    <a href="mailto:test@example.com?subject=my%20subject&amp;body=S%26D">mail me</a>
    

    StringEscapeUtils.escapeHtml(String str) from Apache Commons Lang.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get UTF-8 working in my Java webapp (servlets + JSP, no
I have a java webapp that has to be deployed on either Win or
I have a java webapp which needs to upload files via http and then
I have a Java EE webapp that works perfectly when I run it on
I have to use 3 different transaction managers in my webapp. So I wrote
I have a java webapp on localhost:8086 that sends and receives webservices to localhost:9080.
(Java Spring WebApp) I have: public class PersonValidator implements Validator { private PersonDAO d;
Due project requirements, I need to create a webapp that, when executing, will allow
url = new java.net.URL(s) doesn't work for me. I have a string C:\apache-tomcat-6.0.29\webapps\XEPServlet\files\m1.fo and
We have a Java webapp that talks to an Oracle database. We are keeping

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.