Facelets charset problem

旧街凉风 提交于 2020-01-06 03:15:26

问题


In my earlier post there was a problem with JSF charset handling, but also the other part of the problem was MySQL connection parameters for inserting data into db. The problem was solved.

But, I migrated the same application from JSP to facelets and the same problem happened again. Characters from input fields are replaced when inserting to database (č is replaced with Ä), but data inserted into db from sql scripts with proper charset are displayed correctly. I'm still using registered filter and page templates are used with head meta tag as following:

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-2">

If I insert into h:form tag the following attribute:

acceptcharset="iso-8859-2"

I get correct characters in Firefox, but not in IE7.

Is there anything else I should do to make it work?

Thanks in advance.


回答1:


Add the following line to the filter:

response.setContentType("text/html;charset=ISO-8859-2");

Don't use acceptcharset attribute. IE has serious bugs with it.

Also, when you're using a <?xml?> declaration in top of Facelets XHTML page, ensure that it's using the desired charset or just remove the whole declaration, it's not strictly required.

<?xml version="1.0" encoding="ISO-8859-2"?>



回答2:


i think you can see the implementation of org.springframework.web.filter.CharacterEncodingFilter and you can start your tomcat by adding -Dfile.encoding=ISO-8859-2 as jvm arguments



来源:https://stackoverflow.com/questions/3005106/facelets-charset-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!