Arabic text in managed bean

99封情书 提交于 2020-01-07 05:39:46

问题


In my application I use Spring, JPA Hibernate, JSF the problem is when I write an Arabic text and find it in manged Bean like (ÙابÙÙÙ) I use Tomcat v 7.0 Server

Web.xml

<filter>
    <filter-name>encoding-filter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>utf-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>encoding-filter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>

Form is

<h:form dir="rtl" acceptcharset="UTF-8">

before Head

<?xml version="1.0" encoding="UTF-8"?>

In head of page.

<f:view locale="TR" encoding="UTF-8" contentType="text/html" />
<meta http-equiv="content-type" content="text/html;charset=utf-8" />

I use @Named in managed bean @MangedBean and @Component are not right too.

MySQL database are good I read from it Arabic text correctly.

In constructor,

HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpServletResponse res = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();

try {
    req.setCharacterEncoding("UTF-8");
    res.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Please any hint to take a valid Arabic text. Thanks in advance.


回答1:


i solve the problem when i used tomcat encoding filter

<filter>
    <filter-name>SetCharacterEncoding</filter-name>
    <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>ignore</param-name>
        <param-value>false</param-value>
    </init-param>
</filter>
<filter>
    <filter-name>Conversation</filter-name>
    <filter-class>org.jboss.weld.servlet.ConversationFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>SetCharacterEncoding</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
    <filter-name>Conversation</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>


来源:https://stackoverflow.com/questions/33474599/arabic-text-in-managed-bean

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