【问题标题】:How to encode a string to UTF8 and then display it correctly in html? [duplicate]如何将字符串编码为 UTF8,然后在 html 中正确显示? [复制]
【发布时间】:2019-10-12 18:20:05
【问题描述】:

我有一个程序,其中一个表格显示在屏幕上。只要没有重音,内容就会正确显示。

这是我的代码

StringBuffer sBuff = new StringBuffer();
if(!("CSV".equalsIgnoreCase(exportFormat) || "HTML".equalsIgnoreCase(exportFormat))){
        sBuff.append("<p title=\""+displayparseado+"\">");
        sBuff.append(displayparseado);
        sBuff.append("</p>");
}
else{
        sBuff.append(display);
}

我也试过解析字符串。

byte arr[] = display.getBytes("UTF-8");
String displayparseado = new String(arr);

预期输出:Descripción de prueba。

实际输出:

一个注释;我不能使用外部库。

【问题讨论】:

  • 你在前端使用百里香吗?
  • 看起来你逃离了你的sBuff。不要这样做,

标签: java rest jsp


【解决方案1】:

尝试StringEscapeUtils 转义您的 html 字符串。到目前为止,这对我来说做得很好。

【讨论】:

  • 谢谢,但我不能使用外部库。
猜你喜欢
  • 2020-11-25
  • 1970-01-01
  • 1970-01-01
  • 2014-07-13
  • 2013-10-26
  • 1970-01-01
  • 1970-01-01
  • 2011-10-13
  • 1970-01-01
相关资源
最近更新 更多