这是一个使用 seam 2.2 构建的应用程序,它在 Jboss 4.1.2 下完美运行。由于我的 ISP 的支持,我必须将 JBoss 升级到 5.1 版。我确实尝试在 JBoss 5 下运行相同的应用程序,一切看起来都很好,但只有一件事失败了。
它是一段代码,它生成一些 JSon 以提供使用Open Flash Chart 库构建的图表。我还使用JOFC 库为这些图表生成 JSon。好吧,我们使用的方法基本上有一个接缝工厂,它打印一个 JSon,然后我们在一个空白的 .xhtml 页面中引用这个工厂,图表从该页面加载所需的 JSon 以正确呈现。按照一些片段:
调用 seam 工厂的 xhtml 页面:
<f:view xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
contentType="text/json; charset=UTF-8">
#{jsonGraficoPesoUsuario}
</f:view>
生成 JSON 字符串的工厂方法:
@Factory("jsonGraficoPesoUsuario")
public String graficoPesoUsuario()
{
...
String jsonString = chart.toString();
log.info("JSonString ==>> " + jsonString);
// try {
// jsonString = URLEncoder.encode(jsonString, "UTF-8");
// } catch (UnsupportedEncodingException e) {
// log.error("Erro ao tentar fazer o encode da string json ==>> " + e.getMessage());
// e.printStackTrace();
// }
return jsonString;
好吧,代码还显示我们在发送之前尝试过对 json 字符串进行编码,但还是没有成功。在将 json 打印到 log.info 的行中,json 字符串被完美地保留了下来,但是使用 JBoss5 时会发生“(双引号)字符被 html 转义字符替换。
下面的 json 字符串有望正确地提供图表,并且在 jboss4 下表现正确:
{"y_axis":{"min":100,"colour":"#96A9C5","grid-colour":"#DDDEE1","max":112},"title":{"text"
:"Gráfico de evolução de Peso"},"bg_colour":"#FFFFFF","is_decimal_separator_comma":1,"elements":[{"text":"Peso","values":[100.5,101.5,102.5,
102,103,107,109,110.5,108],"font-size":10,"type":"line","tip":"Linha do Peso"}],"num_decimals":2,"is_fixed_num_decimals_forced":1,"x_axis":{
"colour":"#96A9C5","grid-colour":"#DDDEE1","labels":{"rotate":"-24","labels":["01/05/10","15/05/10","25/05/10","01/06/10","09/06/10","25/06/
10","05/07/10","10/07/10","20/07/10"]}},"is_thousand_separator_disabled":0}
但与使用 JBoss5 相比,会打印以下字符串,请注意双引号的 html 编码替换:
{"y_axis":{"min":100,"colour":"#96A9C5","grid-colour":"#DDDEE1","max":112},"title":{"text":"Gráfico de evolução de Peso"},"bg_colour":"#FFFFFF","is_decimal_separator_comma":1,"elements":[{"text":"Peso","values":[100.5,101.5,102.5,102,103,107,109,110.5,108],"font-size":10,"type":"line","tip":"Linha do Peso"}],"num_decimals":2,"is_fixed_num_decimals_forced":1,"x_axis":{"colour":"#96A9C5","grid-colour":"#DDDEE1","labels":{"rotate":"-24","labels":["01/05/10","15/05/10","25/05/10","01/06/10","09/06/10","25/06/10","05/07/10","10/07/10","20/07/10"]}},"is_thousand_separator_disabled":0}
我已经检查了操作系统区域设置,并且还在 jboss http 通道上进行了配置,以对 server.xml 中的正文进行编码:
<!-- A HTTP/1.1 Connector on port 8080 -->
<Connector protocol="HTTP/1.1" port="8080" address="${jboss.bind.address}"
connectionTimeout="20000" redirectPort="8443" useBodyEncodingForURI="true"/>
它没有用。我们对应用程序中的所有资源和页面使用 UTF-8。
有什么线索吗?
提前发送。[]s