Problem description
Eclipse project, SSM, front fill form (form element), submit the filled Chinese “delivery address”, save in the database, there is a problem of Chinese garbled code
(Data table is garbled, read from database to page is also garbled)
may
1. Eclipse project coding format (this estimate has the most impact)
Modify the coding format of the Eclipse project
Note: Eclipse under Windows default code for GBK.
Note: If you don’t mind the Chinese comments in the project are all scrambled, you can modify them directly. If you don’t mind, it is recommended to create a new project and overwrite the SRC and WebContent folders of the new project with the SRC and WebContent folders of the original project
2. Modify Tomcat’s server.xml (this is also important)
1) With a text editor (such as Notepad), open the server.xml in the conf folder under the Tomcat installation directory
Note: If you don’t remember the installation path, you can search for Tomcat – with Everything software
2) Search ConnectionTimeout =”20000″ and UriEncoding =”UTF-8″ to save the file.
3. Encoding =UTF8 for database connection
1) If you configure the data source directly in ApplicationContext.xml, check the URL values
Is at the bottom of the < property name = “url” value = “JDBC: mysql: / / localhost: 3306 / easymall? CharacterEncoding =utf8″/> Check if characterEncoding=utf8 is written
<! - configuration data source - > < bean id = "dataSource" class = "HTTP: / / org.apache.com mons. Dbcp2. BasicDataSource" > < property name = "driverClassName." value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/easymall?characterEncoding=utf8"/> <property name="username" value="root"/> <property name="password" value="12345678"/> <! - the maximum number of connections - > < property name = "maxTotal" value = "30" / > <! - the largest number of idle connections - > < property name = "maxIdle" value = "10" / > <! > <property name="initialSize" value="5"/> </bean>
Note (pretty, tread pit, so add that the light spray) : don’t write < property name = “url” value = “JDBC: mysql: / / localhost: 3306 / easymall? UseUnicode = = true&characterEncoding utf8 “/ > or < property name =” url “value =” JDBC: mysql: / / localhost: 3306 / easymall? � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � �? Don’t just read the error message on the last block.)
I’m just adding useUnicode=true, ①BeanFactory not initialized or already closed – call ‘refresh’ before the basic beans via the ApplicationContext
②Server Tomcat v9.0 Server at localhost failed to start.
I turned to the applicationContext.xml and found that it had already prompted me to use the URL to connect to the database in the applicationContext.xml. The server failed to start because it should not be written to the delimiter
2) If you are loading a configuration file, change the encoding of the URL in the configuration file
Specific reference to this article: SSM to solve the problem of Chinese stored in the database garbled code (record your own problem)
4. Add UTF8 to the JSP view (be careful when creating a new JSP file)
General in the new JSP attention to change to the line (generally ISO-8859-1
PageEncoding setting at the top of the file
<%@ page language=”java” import=”java.util.*” pageEncoding=”utf-8″%>
5. Add some configuration code to the project’s web.xml (not a big impact)
Note: The value of the filter-name in the filter is the same as the value of the filter-name in the filter mapping
<! > <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>
reference
Resolve the situation that the Chinese from SpringMVC reception front end appears garbled
SSM solves the problem of garbled code stored in Chinese database (record your problems)
IDEA is a permanent solution to the problem of inserting Chinese data garbled into the database
BeanFactory not initialized or already closed – call ‘refresh’ before access … The solution to this problem