JSF2 UTF-8 Encoding issue with saving data into database

I have added below code in my web.xml file

  <filter>
      <filter-name>forceUTF8CharSet</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>
    </filter>

    <filter-mapping>
      <filter-name>forceUTF8CharSet</filter-name>
      <url-pattern>*</url-pattern>
    </filter-mapping>

In database i have made these changes

CREATE TABLE `group_distribution` (
  `gd_id` int(11) NOT NULL,
  `gd_tweet` varchar(500) CHARACTER SET utf8 NOT NULL,
  `gd_ht` varchar(45) CHARACTER SET utf8 DEFAULT NULL,
  `gt_created_by` int(11) DEFAULT NULL,
  `gt_team_lead` int(11) DEFAULT NULL,
  `gt_send_to` int(11) DEFAULT NULL,
  `gt_added_dt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `gt_update_dt` timestamp NULL DEFAULT NULL,
  `gt_active_flag` tinyint(1) NOT NULL,
  PRIMARY KEY (`gd_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

and when i am maually inserting data into Db through MySQL Client its working fine but when i am inserting same data with JSF page database showing data like this

??????? ?? ?????? ?? ???????? ?????? ?? ?????? ???? ????? ??? ????? ???????? ??? ?? ?????? ?? ??? ???? ??? Test data

Also in template file i added this line

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

JSF page able to show data in Hindi font but same data when going to Db showing ???????

Answers


Thanks to Primefaces Group member in Facebook Got the solution in my application-context.xml file i changed the jdbc url

<property name="jdbcUrl" value="jdbc:mysql://ipaddress:3306/ccc?useUnicode=true&amp;characterEncoding=utf-8" />

Which was look like below previously

<property name="jdbcUrl" value="jdbc:mysql://ipaddress:3306/ccc " />

Try to add this to web.xml

  <jsp-config>
    <jsp-property-group>
      <url-pattern>*.*</url-pattern>
      <page-encoding>UTF-8</page-encoding>
    </jsp-property-group>
  </jsp-config>

in tomcat/config/server.xml file add the URIEncoding="UTF-8" to the connector as the following:

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" 
           URIEncoding="UTF-8"/>

Need Your Help

Dump X clipboard data with GTK+ or PyGTK

gtk clipboard pygtk x11

How do I paste HTML data from the X clipboard using PyGTK/GTK+?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.