如何将 JBoss 5 编码设置为像以前的 JBoss 4.1 一样?
它是一个使用seam 2.2构建的应用程序,并且在Jboss 4.1.2下完美运行。由于我的 ISP 的支持,我必须将 JBoss 升级到版本 5.1。我确实尝试在 JBoss 5 下运行相同的应用程序,一切看起来都很好,但有一件事失败了。
它是一段代码,生成一些 JSon 来提供使用 打开 Flash 图表库构建的图表。我还使用 JOFC 库 为这些图表生成 JSon。好吧,我们使用的方法基本上有一个打印 JSon 的接缝工厂,然后我们在空白的 .xhtml 页面中引用该工厂,图表从该页面加载正确渲染所需的 JSon。遵循一些片段:
调用接缝工厂的 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
It is an application that has been built using seam 2.2 and it is running perfectly under Jboss 4.1.2. Because of support from my ISP I will have to upgrade JBoss to version 5.1 . I did try to run same app under JBoss 5 and everything looked fine but one single thing failed.
It is a piece of code that generates some JSon to feed a Chart built using Open Flash Chart libraries. I also use JOFC libraries to generate the JSon for these charts. Well the approach we have used basically has a seam factory which prints a JSon and than we do reference this factory in a blank .xhtml page from where the chart loads the required JSon to render properly. Follow some snippets:
The xhtml page where the seam factory gets called:
<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>
The factory method which generates the JSon string:
@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;
Well the code shows also that we have tryied encoding the json string before sending but again no success. In the line where it is printed json to log.info the json string is perfectly preserved, but using JBoss5 what happens is that the " (double quote) chars are replaced by html escape characters.
The follow json string is expected to properly feed the chart and this behaves correctly under 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}
But than using JBoss5 the follow string is printed, notice the html encode replacement for double quotes:
{"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}
I have already checked O.S locale and also did a configuration on jboss http channel to encode the body in 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"/>
It didn't work. We use UTF-8 for all resources and pages in our app.
Any clues?
Tx in advance.
[]s
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我查看了 jsf 文档并进行了审查,发现了 f:verbatim 标签。它解决了这个问题。现在,打印 json 字符串的 .xhtml 页面如下所示:
现在结果 json 字符串没有更改,并且图形可以正确呈现。
[]s
I took a look at jsf documentation to review it and found f:verbatim tag. It fixed the issue. Now my .xhtml page where the json string is printed is like:
Now the result json string is not changed and the graphic renders properly.
[]s
我不知道这是否有帮助,但我会尝试。
在 Components.xml 中设置
创建一个过滤器,将所有内容设置为 UTF-8
并在 web.xml 中启用此过滤器
如果这没有帮助,您可以手动编码字符串
我不确定正则表达式能否正常工作,但您可以尝试。您也许还可以使用 StringEscapeUtils Apache Commons 能够正确转义所有 HTML。
I don't know if this will help, but I will try.
In components.xml set
Create a Filter that will set everything to UTF-8
And enable this filter in web.xml
If this doesn't help, you can manually encode the string
I am not sure the regex will work correctly, but you can try. You can also perhaps use StringEscapeUtils from Apache Commons to correctly escape all HTML.
这样的付出解决了问题。
Giving like this solved the issue.