Environment: Eclipse10, TOMCAT7
Project: Spingmvc+hibernate+mysql
Encoding: foreground and Database Same code: UTF-8
Programming Language: Java
One, the background value garbled problem.
1.jsp data to the background post the way Chinese garbled.
The Web. xml file adds the following code to solve the garbled problem of post-value-passing.
1 <Filter> 2 <Filter-name>Encodingfilter</Filter-name> 3 <Filter-class>Org.springframework.web.filter.CharacterEncodingFilter</Filter-class> 4 <Init-param> 5 <Param-name>Encoding</Param-name> 6 <Param-value>UTF-8</Param-value> 7 </Init-param> 8 <Init-param> 9 <Param-name>Forceencoding</Param-name> Ten <Param-value>True</Param-value> One </Init-param> A </Filter> - <filter-mapping> - <Filter-name>Encodingfilter</Filter-name> the <Url-pattern>/*</Url-pattern> - </filter-mapping>
2, JSP data to the background get the way the Chinese garbled.
Second, JS file garbled problem.
1. Select the JS file, right-click the property, and change the encoding to UTF-8.
2.jsp page: <script src= "${ctx}/view/js/login.js" type= "Text/javascript" charset=utf-8></script>
Ps:
1.SRC can also use absolute paths
2.${CTX} The data sent in the background is: String Ctx=request.getcontextpath ();
Three, style problems.
Add the following code to Springmvcservlet-servlet.xml.
1 <Mvc:annotation-driven/> 2 <mvc:resourcesMapping= "/view/css/**" Location= "/view/css/" />3 <mvc:resourcesMapping= "/view/images/**" Location= "/view/images/" />4 <mvc:resourcesMapping= "/view/js/**" Location= "/view/js/" />5 <mvc:resourcesMapping= "/kaptcha/**" Location= "/kaptcha/" />
Example: A CSS path is/logistic/view/css/admin.css
Then location= "/view/css/" mapping= "/view/css/**"
Front page: <link href= "/logistic/view/css/admin.css" type= "Text/css" rel= "stylesheet" charset=utf-8>
The logistic is the project name
Iv. Scan the Java package.
Add the following code to Springmvcservlet-servlet.xml.
1 < base-package= "Com.controller"/>2 < Base-package = "Org.cric.util" />
First line: Scan all files with @controller under "Com.controller", including all files with @controller under "Com.controller.login"
Second line: Scan all files with @controller under "Org.cric.util"
Five, the database receives Chinese data.
Applicationcontext.xml inside
Jdbc:mysql://localhost:3306/logistichm
Add the following code:
?useunicode=true& Characterencoding=utf-8
That
jdbc:mysql://localhost:3306/logistichm?useunicode=true& Characterencoding=utf-8
1 < property name = "url" > 2 < value > jdbc:mysql://localhost:3306/logistichm?useunicode=true< Span style= "color: #ff0000;" >& characterencoding=utf-8 3 </ value > 5 </ property >
Summary of SPINGMVC problems