Summary of SPINGMVC problems

Source: Internet
Author: User

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&amp; Characterencoding=utf-8
That
            jdbc:mysql://localhost:3306/logistichm?useunicode=true&amp; Characterencoding=utf-8

 1  <  property  name  = "url"  >  2  <  value  >  jdbc:mysql://localhost:3306/logistichm?useunicode=true< Span style= "color: #ff0000;" >&amp;  characterencoding=utf-8  3  </ value  >  5  </ property  >  

Summary of SPINGMVC problems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.