web project garbled solution

In doing web projects, we often encounter the problem of Chinese and Chinese garbled mass participation garbled, where a finishing solution

First, the cause garbled pages and pass parameters will appear: page after web servers, browsers handle, so resulting in transcoding or garbled reasons, may involve: setting the page itself, set up a web server, browser settings


1, set the page encoding:
  (a) is a jsp page, for this, we need to add in the head jsp page encoding settings XML / HTML code
?

1
[size=1em]   [size=1em]<%@ page contentType="text/html;charset=UTF-8" trimDirectiveWhitespaces="true" language="java" %>
 




  (B) page is html, html head meta tags plus: XML / HTML code
?

1
[size=1em]< [size=1em]meta  [size=1em]http-equiv [size=1em]= [size=1em]"Content-Type"  [size=1em]content [size=1em]= [size=1em]"text/html; charset=utf-8"  [size=1em]/>
 




  (C) If jsp, c is introduced: import manner, in tomcat is no problem, but in weblogic easily garbled, for example: XML / HTML code
?

1
[size=1em]< [size=1em]c:import  [size=1em]url [size=1em]= [size=1em]"/jsp/system/panelBar.jsp"  [size=1em]charEncoding [size=1em]= [size=1em]"UTF-8" [size=1em]></ [size=1em]c:import [size=1em]>   
 



Here I remember plus encoding settings
also refer to the article: the interpretation and pageEncoding contentType set
                        depth analysis of Chinese coding java web

2, web server settings and program settings:
(A) project web.xml encoding settings: page displays garbled and mass participation , may be not web.xml configuration request code, where the need to add the following configuration on the ok:
the Java code
?

1
 
2
 
3
 
4
 
5
 
6
 
7
 
8
 
9
 
10
 
11
 
12
 
13
 
14
 
15
 
16
 
17
 
18
 
19
 
20
[size=1em]<!--spring编码过滤器start -->
[size=1em]     [size=1em]<filter>
[size=1em]         [size=1em]<filter-name>encodingFilter</filter-name>
[size=1em]         [size=1em]<filter- [size=1em]class [size=1em]>
[size=1em]             [size=1em]org.springframework.web.filter.CharacterEncodingFilter
[size=1em]         [size=1em]</filter- [size=1em]class [size=1em]>
[size=1em]         [size=1em]<init-param>
[size=1em]             [size=1em]<param-name>encoding</param-name>
[size=1em]             [size=1em]<param-value>UTF- [size=1em]8 [size=1em]</param-value>
[size=1em]         [size=1em]</init-param>
[size=1em]         [size=1em]<init-param>
[size=1em]             [size=1em]<param-name>forceEncoding</param-name>
[size=1em]             [size=1em]<param-value> [size=1em]true [size=1em]</param-value>
[size=1em]         [size=1em]</init-param>
[size=1em]     [size=1em]</filter>
[size=1em]     [size=1em]<filter-mapping>
[size=1em]         [size=1em]<filter-name>encodingFilter</filter-name>
[size=1em]         [size=1em]<url-pattern>/*</url-pattern>
[size=1em]     [size=1em]</filter-mapping>
[size=1em]     [Size = 1em] <-! Spring encoding filter end ->
 





(B) tomcat's service.xml plus encoding settings: For garbled, who also mishandled directly said no problem, if the above can not solve, modifying tomcat configuration, when the port settings, plus encoding settings, as follows:
Text code Plain
?

1
[size=1em]<Connector port="8080"  protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" URIEncoding="UTF-8" />
 





(C) if the project is deployed on linux, linux can see the code, the command: / etc / sysconfig / i18n (no authority is not visible), results are as follows:
Plain Text code
?

1
 
2
 
3
[size=1em]LANG="zh_CN.UTF-8"  
[size=1em]SUPPORTED="zh_CN.UTF-8:zh_CN:zh"  
[size=1em]SYSFONT="latarcyrheb-sun16"
 





(D) If an application server is weblogic (this is my most troublesome), where the need to add the following configuration in weblogic.xml:
XML / HTML code
?

1
 
2
 
3
 
4
 
5
 
6
[size=1em]< [size=1em]charset-params [size=1em]>
[size=1em]< [size=1em]input-charset [size=1em]>
[size=1em]< [size=1em]resource-path [size=1em]>/*</ [size=1em]resource-path [size=1em]>
[size=1em]< [size=1em]java-charset-name [size=1em]>UTF-8</ [size=1em]java-charset-name [size=1em]>
[size=1em]</ [size=1em]input-charset [size=1em]>
[size=1em]</ [size=1em]charset-params [size=1em]>
 





(e)其他程序编码设置,比如设置request.setCharacterEncoding("utf-8"); 等等。切记,页面请求时,get请求很容易出现中文乱码问题。能post提交就post,不能的话,就要考虑编码问题了


3、浏览器设置编码
很多浏览器都有默认编码,我们可以选择和切换,例:chrom修改编码:选择右上角的三条横岗——>更多工具——>编码——>选择你需要的编码格式

发布了965 篇原创文章 · 获赞 11 · 访问量 3万+

Guess you like

Origin blog.csdn.net/xiaoyaGrace/article/details/105285454