代码之家  ›  专栏  ›  技术社区  ›  Patrick Kwinten

向Xpages发送UTF-8消息

  •  0
  • Patrick Kwinten  · 技术社区  · 4 年前

    我有一个针对瑞典用户的XPages应用程序。

    当我通过

    msg = propStrings.getProperty("gen_CustDateDecided") ;
    FacesContext facesContext = FacesContext.getCurrentInstance();
    facesContext.addMessage("msgBox", new javax.faces.application.FacesMessage(msg));
    

    广播的文本驻留在属性文件中,采用UTF-8编码。

    加载属性文件时,我确保以UTF格式读取:

    private Properties getPropertiesFromFile(String fileName) {
            Properties prop = new Properties();
            try {
                InputStream is = FacesContextEx.getCurrentInstance().getExternalContext().getResourceAsStream(fileName);
                BufferedReader r = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                prop.load(r);
            } catch (Exception e) {
                XspOpenLogUtil.logEvent(null, null, fileName, Level.WARNING, null);
            }
            return prop;
        }
    

    Xpage上messages控件上显示的文本: 我是昆德克姆姆姆特先生

    属性文件中的文本: gen_Custdatedetermined=Senaste beslutsdatum i kundkommittÃn

    我做错了什么?

    0 回复  |  直到 4 年前
        1
  •  1
  •   stwissel    4 年前

    属性文件未编码为UTF-8。它们是ISO 8859-1。你需要对它们进行相应的编码。最简单的方法是在独立的Java类中使用几行代码来保存属性。负责编码。

    更多详情请点击此处: How to use UTF-8 in resource properties with ResourceBundle

    推荐文章