Spring Hibernate H2数据库编码

时间:2014-06-10 11:07:46

标签: java spring hibernate h2

我从H2数据库中读取阿拉伯语字符时出现编码问题,我在页面中看到了?????????

即使我在几个地方配置了UTF-8

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> 

在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> 

并在JSP页面中

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

也在实体的吸气剂中

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

我已经没有想法了,请帮忙吗?

0 个答案:

没有答案