简体   繁体   中英

JAVA MessageFormat.Format with umlauts (ä / ö / ü)

I have a problem with MessageFormat.format in my Java backend. I have there a mailing function which sends mails with content from my frontend (passend via api to the backend) to some users.

String text =
    MessageFormat.format(
        "Dear Report Owner\n\nA new access request:\n\nFrom: {0} {1} ({2})\nFor: {3} \nReason: {4}\n\nPlease process the access request and inform {0} {1} accordingly.\n\nBest regards,\nDev-Team",
        accessTokenUser.getGivenName(),
        accessTokenUser.getFamilyName(),
        accessTokenUser.getEmail(),
        processedRoleContent,
        processedLinkContent);

It's possible, that some values (eg processedRoleContent ) contains for example ü but in the sent email it appears as Ü .

How can I configure the MessageFormat.format that it send's umlauts?

Thank you in advance!

Consider the following minimal demonstration of why I think MessageFormat.format has nothing to do with your problem:

import java.text.MessageFormat;

public class Application {

    public static void main(String[] args) {
        System.out.println(MessageFormat.format("{0}", "ü"));
    }
}

which results at my machine in the output ü .

So, I think your E-Mail function escapes Umlauts as HTML entities.

您可以为任何类型的字符串转换字节然后 UTF-8。

new String(out.toByteArray(), "UTF8")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM