我无法正确阅读我的字符串。 DB返回=Љ дҐ "Ђи®вЁЄ"
而不是普通文本。我可以在服务器控制台中看到这个垃圾文本,所以我不认为页面编码存在问题。这是我的配置:
<beans:bean id="dataSourceMain" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<beans:property name="driverClass" value="org.postgresql.Driver" />
<beans:property name="jdbcUrl" value="jdbc:postgresql://192.168.101.158:5432/cafe" />
<beans:property name="user" value="postgres" />
<beans:property name="password" value="mypassword" />
<beans:property name="minPoolSize" value="5" />
<beans:property name="maxPoolSize" value="8" />
<beans:property name="preferredTestQuery" value="SELECT 1" />
<beans:property name="acquireIncrement" value="1" />
<beans:property name="idleConnectionTestPeriod" value="100" />
<beans:property name="maxStatements" value="0" />
<beans:property name="checkoutTimeout" value="60000" />
</beans:bean>
<beans:bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSourceMain" />
<beans:property name="configLocation">
<beans:value>/WEB-INF/db/hibernate.cfg.xml</beans:value>
</beans:property>
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.connection.characterEncoding">UTF-8</beans:prop>
<beans:prop key="hibernate.connection.charSet">UTF-8</beans:prop>
<beans:prop key="hibernate.connection.useUnicode">true</beans:prop>
<beans:prop key="hibernate.show_sql">false</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
我也在我的web.xml中找到了这个:
<filter>
<filter-name>CharacterEncodingFilter</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>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>SetCharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncodingFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>
我创建db的查询:
CREATE DATABASE "cafe"
WITH OWNER "postgres"
ENCODING 'UTF8';
可能出现什么问题?