求救!JQuery ajax的post方法向action传文件路径出现乱码(非中文乱码)

ssun125 2012-07-29 07:41:38
WEB服务器是Tomcat7,使用了struts框架
在Jquery中使用post方法给服务器发送数据出现乱码,具体代码就现象如下:
js代码:
function loadChild(val){
//alert();
$.post('backstage/resource/toloadChild', {
path : "D:\tomcat-7.0.27\webapps\dssx\front\data\exam"
}, function(data) {
alert(data);
}, "xml");
}

Action中的接收代码:
public String loadChild() throws UnsupportedEncodingException{
request = ServletActionContext.getRequest();
request.setCharacterEncoding("utf-8");//没有这句也是乱码
File file = new File(request.getParameter("path"));
System.out.println(file.getPath());
return SUCCESS;
}
乱码如下:
D: omcat-7.0.27webappsdssxrontdataexam
如果js中用escape("D:\tomcat-7.0.27\webapps\dssx\front\data\exam")的话,就是这样的:
D%3A%09omcat-7.0.27webappsdssx%0Crontdataexam
网页都是使用UTF-8编码


...全文
261 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
gzqGyula 2012-07-30
  • 打赏
  • 举报
回复
用下面试试:
HttpServletResponse response = ServletActionContext.getResponse();
response.setCharacterEncoding("UTF-8");
ssun125 2012-07-29
  • 打赏
  • 举报
回复
大哥呀,现在我找到一个解决办法了,只要把路径的反斜杠换成正斜杠就可以了,还是谢谢你呀。
ssun125 2012-07-29
  • 打赏
  • 举报
回复
大哥呀,我刚刚试了,好像还是一样的结果
licip 2012-07-29
  • 打赏
  • 举报
回复
你在struts.xml文件中加:
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
这样就可以解决了。

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧