AJAX Chinese hash issues
Related Tags:
A hash of the reasons for using the XMLHTTP object Post form, is the default with UTF-8 characters sent. If you have a website is to use the UTF-8 encoded, then receive the data is normal if your page coding is GB2312 the case, the problem has come, and the data from POST UTF-8, and the entire site you GB2312 is used to show, then all the Chinese characters will all become garbled.
The solution:
Used for filtration UTF-8 encoded on the trip.
Simple example:
Public class Encode
Implements Filter
(
Protected String encoding = "GBK";
Protected FilterConfig filterConfig = null;
/ **
* Client will report Encoding settings ignored, we set up the mandatory use of the Encoding?
* The default is to ignore
* /
Protected boolean ignore = true;
Implements Filter
(
Protected String encoding = "GBK";
Protected FilterConfig filterConfig = null;
/ **
* Client will report Encoding settings ignored, we set up the mandatory use of the Encoding?
* The default is to ignore
* /
Protected boolean ignore = true;
Public void destroy ()
(
This.encoding = null;
This.filterConfig = null;
)
(
This.encoding = null;
This.filterConfig = null;
)
/ **
* On the current request for encoding settings (if the client does not choose to ignore it installed)
* @ Param request with the current SevletRequest
* @ Param result of the current processing SevletResponse
* @ Param chain linked the current Filter
* @ Exception IOException I / O error occurred
* @ Exception ServletException Servelt mistakes in the future
* /
Public void doFilter (ServletRequest request, ServletResponse response,
FilterChain chain)
Throws IOException, ServletException
(
/ / If installing a cover client or the client settings set to null, the application
/ / Current encoding settings (read from the initialization parameters)
If (ignore | | (request.getCharacterEncoding () == null))
(
String encoding = selectEncoding (request);
* On the current request for encoding settings (if the client does not choose to ignore it installed)
* @ Param request with the current SevletRequest
* @ Param result of the current processing SevletResponse
* @ Param chain linked the current Filter
* @ Exception IOException I / O error occurred
* @ Exception ServletException Servelt mistakes in the future
* /
Public void doFilter (ServletRequest request, ServletResponse response,
FilterChain chain)
Throws IOException, ServletException
(
/ / If installing a cover client or the client settings set to null, the application
/ / Current encoding settings (read from the initialization parameters)
If (ignore | | (request.getCharacterEncoding () == null))
(
String encoding = selectEncoding (request);
If (encoding! = Null)
(
Request.setCharacterEncoding (encoding);
)
)
(
Request.setCharacterEncoding (encoding);
)
)
Chain.doFilter (request, response);
)
)
/ **
* Initialization
* @ Param filterConfig Filter Settings Object
* /
Public void init (FilterConfig filterConfig)
Throws ServletException
(
* Initialization
* @ Param filterConfig Filter Settings Object
* /
Public void init (FilterConfig filterConfig)
Throws ServletException
(
This.filterConfig = filterConfig;
This.encoding = filterConfig.getInitParameter ( "encoding");
String value = filterConfig.getInitParameter ( "ignore");
If (value == null)
(
This.ignore = true;
)
Else if (value.equalsIgnoreCase ( "true"))
(
This.ignore = true;
)
Else if (value.equalsIgnoreCase ( "yes"))
(
This.ignore = true;
)
Else
(
This.ignore = false;
)
This.encoding = filterConfig.getInitParameter ( "encoding");
String value = filterConfig.getInitParameter ( "ignore");
If (value == null)
(
This.ignore = true;
)
Else if (value.equalsIgnoreCase ( "true"))
(
This.ignore = true;
)
Else if (value.equalsIgnoreCase ( "yes"))
(
This.ignore = true;
)
Else
(
This.ignore = false;
)
)
/ **
* <b> Function: to return to the current settings Encoding </ b> <br>
*
* @ Param
* @ Return
* @ Exception
* /
* <b> Function: to return to the current settings Encoding </ b> <br>
*
* @ Param
* @ Return
* @ Exception
* /
Protected String selectEncoding (ServletRequest request)
(
Return (this.encoding);
)
(
Return (this.encoding);
)
)
Deployment description:
Deployment description:
<filter>
<filter-name> Encoding </ filter-name>
<filter-class> Com.pub.dragon.sys.Encode </ filter-class>
<init-param>
<param-name> Encoding </ param-name>
<param-value> UTF-8 </ param-value>
</ Init-param>
<init-param>
<param-name> Ignore </ param-name>
<param-value> True </ param-value>
</ Init-param>
</ Filter>
<filter-name> Encoding </ filter-name>
<filter-class> Com.pub.dragon.sys.Encode </ filter-class>
<init-param>
<param-name> Encoding </ param-name>
<param-value> UTF-8 </ param-value>
</ Init-param>
<init-param>
<param-name> Ignore </ param-name>
<param-value> True </ param-value>
</ Init-param>
</ Filter>
<filter-mapping>
<filter-name> Encoding </ filter-name>
<url-pattern> / * </ Url-pattern>
</ Filter-mapping>
<filter-name> Encoding </ filter-name>
<url-pattern> / * </ Url-pattern>
</ Filter-mapping>
Another very important point is, if returned to the XML format so we must bring <? Xml version = "1.0" encoding = "GBK"> Otherwise customer acceptance will be wrong ...
Related articles:- CSS intensive manual (4)
- Css Manual (6) List List
- CSS quick Manual 3
- CSS intensive manual (7)
- Css Manual (1) Background Background
- Css Manual (2) [Text
- CSS intensive manual (5)
- CSS intensive manual 4
- CSS development manual
- CSS Manual (4) Border Border
- CSS Development Manual [Author: nilxin]
- CSS intensive manual (2)
- Css Manual (c) Font font
- Css Manual (7) Classification Classification
- CSS quick Manual 1
- CSS intensive manual 2
- All commonly used language reference manual for manual HTML | CSS manuals | JScript Manual | VbScript Manual | ASP Manual | PHP Manual | SQL manual | Site effects | ADO Manual
- Chinese typesetting experience CSS
- CSS intensive manual (3)
- Css intensive manual (1)
Post Form jurisdictions to achieve greater than 100 K of data solutions

When the form sent by the tremendous volume of data, it will error. MSDN inspection that the reason is that Microsoft used Request.Form () can receive the maximum data is limited, IIS4 for 80 K bytes, IIS5 for 100 K bytes. Below are several Microsoft solution: ...
Site Promotion of how to play the interactive marketing function Blog

Over the past few days (Note: In this paper the actual completion date for February 22, 2006), Internet insiders who are embedded in the message: GOOGLE launched a Chinese blog, called Google Blackboard. I personally think that domestic enterprises should be touched, especially ...
Simple effect of the production figures Perspective

1. "Space three-dimensional perspective," said White is a small nearly far, look at this painting, the player's eyes are clear near the far smaller feeling. 2. Perspective for a painting, an auxiliary line, this support line is painting the horizon. ...
All woven from the Internet network to the Internet set off a new upsurge in Web2.0

All woven from the Internet network to the Internet set off a new upsurge in Web2.0 ZDNet China Web 2.0 is gradually recovered to the Internet Internet the true meaning of: equality, interaction, to the centre. You should not just the Internet readers...
Creative domain names - talk about domestic unit of Internet domain name in English means

In recent years, with the rapid development of the Internet, more and more Internet users and the Internet as a "house number," the importance of domain names by more and more people understand. According to the newspapers, to the second half of last year, has more than...