﻿<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gavin&#039;s Blog &#187; Struts</title>
	<atom:link href="http://laigw.name/tag/struts/feed" rel="self" type="application/rss+xml" />
	<link>http://laigw.name</link>
	<description>Keep it simple, stupid. Simplicity is beauty.</description>
	<lastBuildDate>Sun, 29 Jan 2012 07:14:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Struts框架下Ajax发送中文乱码问题的解决</title>
		<link>http://laigw.name/post/94.html</link>
		<comments>http://laigw.name/post/94.html#comments</comments>
		<pubDate>Sat, 15 Nov 2008 08:23:36 +0000</pubDate>
		<dc:creator>Gavin</dc:creator>
				<category><![CDATA[Web前端技术]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Struts]]></category>
		<category><![CDATA[中文乱码]]></category>

		<guid isPermaLink="false">http://www.laigw.name/?p=94</guid>
		<description><![CDATA[在使用AJAX向服务器端发送中文数据时，出现乱码，折腾了很久，在网上也找了很多解决办法，比如全站UTF-8编码、请求头编码为中文、使用 javascript中的escape函数等等，但一一试过均无效。在绝望之际，找到了一篇和我的情况比较相近的文章(详见：http: //blog.csdn.net/wallimn/archive/2006/11/12/1380106.aspx)，在详细参考这篇文章的做法之后终于把问题解决。
现在，把自己的解决方法写出来，以便有需要的朋友不要再像我那样走弯路。
环境：WinXP + Eclipse，JSP + Struts，页面用JavaScript结合Ajax控制，页面和服务器都使用UTF-8编码。

MyActionForm的属性：

&#160;查看代码 JAVA1
2
3
4
5
private String nameEn = null;
&#160;
private String nameSc = null;
&#160;
private String nameTc = null;

Action(MyAction) 的excute方法里面代码：

&#160;查看代码 JAVA1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
MyActionForm maForm = &#40;MyActionForm&#41;form;
&#160;
// must decoding, or else it will disorderly code
&#160;
// 第二个设编码参数一定要设
&#160;
String strNameEn = java.net.URLDecoder.decode&#40;maForm.getNameEn&#40;&#41;, &#34;UTF-8&#34;&#41;;
&#160;
String strNameSc = java.net.URLDecoder.decode&#40;maForm.getNameSc&#40;&#41;, &#34;UTF-8&#34;&#41;;
&#160;
String strNameTc = java.net.URLDecoder.decode&#40;maForm.getNameTc&#40;&#41;, &#34;UTF-8&#34;&#41;;
&#160;
System.out.println&#40;&#34;strNameEn: &#34; + strNameEn&#41;;
&#160;
System.out.println&#40;&#34;strNameSc: &#34; + strNameSc&#41;;
&#160;
System.out.println&#40;&#34;strNameTc: &#34; + strNameTc&#41;;

客户端代码：

&#160;查看代码 [...]]]></description>
		<wfw:commentRss>http://laigw.name/post/94.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

