I wrote a small application on Spring MVC where users can enter their data into the database. When launched locally, everything is normally displayed, and when launched on a VPS, the data that is entered by the controller into the database is displayed as (?????? ?? ????).
Added to pom.xml:
<properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> ..... </properties> In 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> In appconfig-mvc.xml:
<beans:bean class = "org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <beans:property name="messageConverters"> <beans:array> <beans:bean class = "org.springframework.http.converter.StringHttpMessageConverter"> <beans:property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" /> </beans:bean> </beans:array> </beans:property> </beans:bean> <!-- Enables the Spring MVC @Controller programming model --> <annotation-driven /> ....... I tried to write when creating a database on the server
CREATE DATABASE mydb
DEFAULT CHARACTER SET utf8
DEFAULT COLLATE utf8_general_ci;
Anyway, there are questions in the database (when I do a SELECT from the database - there are also questions in place of the Russian text).
EDITED: on the JSP page where the save comes from is also worth:
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> connection to the database:
<util:properties id="application" location="classpath:database.properties"/> <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <beans:property name="driverClassName" value="#{application.driverClassName}" /> <beans:property name="url" value="#{application.url}" /> <beans:property name="username" value="#{application.username}" /> <beans:property name="password" value="#{application.password}" /> <beans:property name="maxIdle" value="-1"/> <beans:property name="maxActive" value="-1"/> <beans:property name="maxOpenPreparedStatements" value="-1"/> <beans:property name="maxWait" value="20000"/> <beans:property name="validationQuery" value="SELECT 1"/> <beans:property name="testOnBorrow" value="true"/> </beans:bean>
characterEncodingwhen connecting to the database worth? Add config as connect to the database - MrFylypenko<beans:property name="characterEncoding" value="utf8" />configuration - MrFylypenkojdbc:mysql://localhost:3306/?useUnicode=yes&characterEncoding=UTF-8- MrFylypenko