Spring 3 MVC: How to store € symbol from form?
I am using Spring 3 MVC and MySQL 5 as my DB.
I have created a form using Spring form tags for updating an object in my database.
I enter "Ticket price: €35" into one of this form's text input fields and save the item. Then when I view the item in a display page, the text appears as "Ticket price: ?35".
If I enter "Ticket price: €35" directly into the database using MySql Query Browser, then the euro symbol displays fine through the display page.
What do I need to do so that my Spring form saves the euro symbol correctly to the database?
Update:
Hi, I tried your suggestion, Bozho, with no luck.. my web.xml looks like this:
<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>开发者_C百科
</init-param>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>baseApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>baseApp</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Any further thoughts?
Use the spring character encoding filter. In 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>
And map it to the default servlet
Then, your MySQL connection string should look like this:
jdbc:mysql://localhost/dbName?characterEncoding=utf8
You have to make sure, that the encoding of your string containing the € is set to the correct encoding (same of your table). I would suggest to use UTF-8
精彩评论