`
zhujs
  • 浏览: 101187 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

extjs乱码解决方法

阅读更多
今天在用ext+struts2做东西的时候,出现参数传递乱码情况,Action接收到的参数值始终都是乱码
1.将页面,工程,都设置成utf-8 
2.传参方式也改成post
3.tomcat 也修改成utf-8
4.ext-base.js此处也修改成"application/x-www-form-urlencoded; charset=UTF-8"
5,接收的时候转码String str = new String(str.getBytes("ISO8859-1"),"GBk");
仍然没有解决问题出现乱码,奇怪了,最后发现其实很简单,问题还是出在传参方式上,参数不能直接跟在Action后面,
url: "adOwner/adActivitiesQuery.action?username='<%=username%>",
因为这样传递仍然是采用的get方式,修改为
baseParams:{
								username:'<%=username%>'
							
						},
						proxy:new Ext.data.HttpProxy({
							url: "adOwner/adActivitiesQuery.action",
							method:'POST'
						}),

5.如果还没解决问题,可能是你struts.xml文件里面<constant name="struts.i18n.encoding" value="utf-8" />value设置成了其他编码方式


6.有时候将tomcat字符直接设置成GBK就能解决问题,不知道原因,有知道的请告知,谢谢 extjs 默认传值方式是utf-8
7.formfile表单提交的时候返回值action.result.msg 出现中文乱码,解决方法:
response.setContentType("text/html;charset=utf-8");
	PrintWriter out = response.getWriter();out.write("{success:false,msg:'你选择的文件不是图片格式'}");
	out.flush();
	out.close();

有人说使用response.setContentType("text/json; charset=utf-8");可老是弹出*.action是否保存,使用response.setCharacterEncoding("UTF-8");会报未结束的字符串常量错误

====================
又遇乱码:在使用uri传递中文参数时产生乱码
解决方法:
js
var assetName = form.findField('filter_LIKE_assetName')
								.getValue();
encodeURIComponent(encodeURIComponent(assetName))

此处一定要转两次
java:
URLDecoder.decode(request.getParameter("assetName"),"UTF-8")

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics