EXT同struts2后台交互一个中文问题
时间:2011-03-31 来源:阿彬
后台:
ActionContext context = ActionContext.getContext(); HttpServletResponse response = (HttpServletResponse) context.get(ServletActionContext.HTTP_RESPONSE); response.setCharacterEncoding("UTF-8"); HttpServletRequest request = (HttpServletRequest) context.get(ServletActionContext.HTTP_REQUEST);request.setCharacterEncoding("UTF-8");
response.getWriter().print("{success:false,msg:'上传失败,文件格式错误'}");
前台:
failure: function(form, action){
Ext.MessageBox.updateProgress(1); Ext.MessageBox.hide(); if(action.result.msg){ Ext.Msg.alert('错误', action.result.msg ); }else{ Ext.Msg.alert('错误', '文件上传失败'); } }
这时弹出的窗口是乱码,前后台已经都是UTF-8,在后台print之前增加一句代码解决问题:response.setContentType("text/html; charset=utf-8");
相关阅读 更多 +