Java 如何通过数据库中的Spring Hibernate在文本框中插入古吉拉特语?
我试图使用JavaSpringHibernate项目将古吉拉特邦存储在postgreSQL数据库中,但它存储的是类似这样的内容 俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎 而不是 મોદીના જય-પરાજય પાછળ આ વ્યક્તિનું ભેજુંJava 如何通过数据库中的Spring Hibernate在文本框中插入古吉拉特语?,java,hibernate,spring-mvc,Java,Hibernate,Spring Mvc,我试图使用JavaSpringHibernate项目将古吉拉特邦存储在postgreSQL数据库中,但它存储的是类似这样的内容 俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎俎 而不是 મોદીના જય-પરાજય પાછળ આ વ્યક્તિનું ભેજું 在我的数据库中,编码是UTF-8,如果我在postgreSQL中直接复制粘贴,它将正确存储,但在web应用程序中从html表单复制粘贴,它将无法正确存储 下面是我的hibernate.hbm.cfg文件 <?xml version=
在我的数据库中,编码是UTF-8,如果我在
postgreSQL
中直接复制粘贴,它将正确存储,但在web应用程序中从html
表单复制粘贴,它将无法正确存储
下面是我的hibernate.hbm.cfg
文件
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">
org.postgresql.Driver
</property>
<property name="connection.url">
jdbc:postgresql://192.168.6.51:5432/JayHind?autoReconnect=true&useUnicode=true&createDatabaseIfNotExist=true&characterEncoding=utf-8
</property>
<property name="connection.username">postgres</property>
<property name="connection.password">pshiv</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">10</property>
<!-- SQL dialect -->
<property name="dialect">
org.hibernate.dialect.PostgreSQLDialect
</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">
org.hibernate.cache.NoCacheProvider
</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">update</property>
<property name="hibernate.connection.CharSet">utf8</property>
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
<mapping class="com.models.Role" />
<mapping class="com.models.UserAttempts" />
<mapping class="com.models.UserLogin" />
<mapping class="com.models.UserRole" />
<mapping class="com.models.Program" />
<mapping class="com.models.NationalProgram" />
<mapping class="com.models.StateProgram" />
<mapping class="com.models.OtherProgram" />
<mapping class="com.models.Video" />
<mapping class="com.models.Contact" />
<mapping class="com.models.Heading" />
</session-factory>
</hibernate-configuration>
我还在web.xml中添加了过滤器
<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>
SetCharacterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
编码
UTF8
强制编码
符合事实的
SetCharacterEncodingFilter
*
预期产量
电流输出
上周我不得不面对这个问题,试试这个。 使用“definitivo”可以获得textBox.getText()并转换为UTF-8 字节ptext[]=definitivo.getBytes(“ISO_8859_1”) 字符串值=新字符串(ptext,“UTF-8”)
检查编码,也许?…在我的数据库中,编码是UTF-8,如果我直接在postgreSQL中复制粘贴,它将正确存储,但在web应用程序中的html表单中,它将无法正确存储。在文本框中,我键入Gujarati,但它存储垃圾。在hibernate中,我也使用了编码,但没有Luckt在您描述的堆栈(浏览器、服务器、应用程序、hibernate、postgresql)中有编码和转换层。你必须把每一个都做好。除非你试图隔离问题,否则你可能会被蒙住眼睛。没有好的方法可以帮助你。我使用的是spring hibernate。好的,所以在表单执行的操作中,你必须插入此代码。不,这对我不起作用,我把它放在我的模型pojo类setter中,但不起作用,它正在将字符串转换为“??”尝试在setters中调试de代码,查看在写入
System.out.println(“controller”+heading.getMessage())后得到什么以及转换成什么代码>它在控制台中给了我这个-控制器«控制器«控制器«控制器«控制器»?电脑,个人电脑,个人电脑,个人电脑
<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>