0

i have an encoding problem when reading from the H2 database for arabic charachters i see in my page ?????????

even i configured UTF-8 in several places

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>
    </filter-mapping> 

in Spring servlet.xml

   <bean id="dataSource"
        class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
        p:driverClassName="${jdbc.driverClassName}"
        p:url="${jdbc.databaseurl}"  />


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation">
            <value>classpath:hibernate.cfg.xml</value>
        </property>

        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">create-drop</prop>
                 <prop key="hibernate.connection.useUnicode">true</prop>
             <prop key="hibernate.connection.characterEncoding">UTF-8</prop> 
             <prop key="hibernate.connection.charSet">UTF-8</prop> 
            </props>
        </property>
    </bean> 

and in the JSP page

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

also in the getter of the entity

public String getaName() throws UnsupportedEncodingException {
        return new String(aName.getBytes(),"UTF-8");
    }

I Have run out of ideas ,any Help please?

Dunken
  • 1,311
  • 7
  • 18
  • 30
  • If you are configuring the datasource with spring the `hibernate.connection` properties are useless. Creating new strings all over the place isn't a solution imho. – M. Deinum Jun 10 '14 at 11:23
  • @M.Deinum i don't know exactly where the problem that's why i tried every where,any ideas you have? – Dunken Jun 10 '14 at 11:27
  • Please add the configuration for the datasource and hibernate sessionfactory. – M. Deinum Jun 10 '14 at 11:34
  • Also make sure that the data you store (how is it stored?) is correctly stored. – M. Deinum Jun 10 '14 at 11:36
  • @M.Deinum yes correctly stored manually by me – Dunken Jun 10 '14 at 11:43
  • @M.Deinum Thanks you i have removed the encoding from the getter its working seems its mereged with the filter,i did it before i know about the filter existence in spring – Dunken Jun 10 '14 at 11:57
  • Usually such problems are not related to the database / data source, but to the content encoding of the servlet container / web server / browser. I think you will need to provide more details in this area. – Thomas Mueller Jun 10 '14 at 12:02
  • I guess this is a duplicate of http://stackoverflow.com/questions/3029401/java-servlet-and-utf-8-problem – Thomas Mueller Jun 10 '14 at 12:04

0 Answers0