js传后台action中文乱码处理

public ActionForward confirmTrans(final ActionMapping mapping,
            final ActionForm actionForm, final HttpServletRequest req,
            final HttpServletResponse res) throws Exception {
        String str= decodeToUtf(req.getParameter("str"));
        return null;
        }

public static String decodeToUtf(Object obj) {
        String reStr = obj != null ? obj.toString() : "";
        String regEx = "[+]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(reStr);
        reStr = m.replaceAll("【SPSOFT】+【SPSOFT】");
        try {
            reStr = URLDecoder.decode(reStr, "UTF-8");
            reStr = reStr.replaceAll("【SPSOFT】+【SPSOFT】", "+");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return reStr;
    }
var str= encodeURI(str);
str= encodeURI(str);
var url = path + actionPath + "&str=" + str;
时间: 2024-08-21 07:00:38

js传后台action中文乱码处理的相关文章

get 方法向后台提交中文乱码问题

前端js代码 function searchAll(){      var contentStr = $('#contentStr_id').val();      contentStr =encodeURI(contentStr);      alert(contentStr);      $('#tt').datagrid('options').url='propose!page.action?test=' + contentStr;      $('#tt').datagrid('relo

resin后台输出中文乱码的解决办法!

最近从tomcat移植到resin,发现这东西不错啊! 只是后台输出时有时候中文会乱码. 现在找到resin后台输出中文乱码的解决办法: 编辑conf/resin.con文件: <!--javac compiler="internal" args="-source 1.5"/--> 修改成这样: <javac compiler="javac" args="-encoding utf-8"/> 重启服务器

最近在调用 calendar.js 的时候出现中文乱码! 解决方案

最近写一个小项目的时候:在调用 calendar.js  的时候出现中文乱码! 如图所示: 原因在于: 我的jsp 页面,指定的是 UTF-8 编码,然而,调用的 calendar.js 的编码确实 GBK 编码,所以出现上面的结果. 解决方案: 再引入 JS文件的时候,指定 编码格式: 例如: <script type="text/javascript" src="<%=path %>/admin/images/calendar.js"  cha

页面与后台传递中文乱码问题(java乱码)

1.前台中文传递到后台乱码. 前台不须要处理, 系统一般都会默认把中文转化为ISO-8859-1类型. 仅仅需在后台接受数据是处理 Str为前台传过来的中文字符串: String inputer = new String( Str.getBytes("ISO-8859-1") , "GB2312"); 2.前台不仅包括中文.并且包括特殊字符,假设仅仅在后台转码,比較困难.採用前台转码,那么就採用后台解码的方式处理 var theid = encodeURI(enco

Http请求传json数据中文乱码问题

业务场景:调easyui的dialog打开一个弹窗,传参是用json封装的,而且有中文,然后在极速模式是正常的,在ie11测试发现中文出现乱码了 var params = JSON.stringify(writParamList); top.dialog({ id: 'noticeList', title:'列表', width:900, height:500, url:'${root}/notice/multiNoticeList.do?params='+params, onclose:fun

[转]JSP或servlet中(以及上传下载文件)中文乱码或不显示的解决方案

时间 2014-04-14 14:33:44  CSDN博客 原文  http://blog.csdn.net/xby1993/article/details/23677375 主题 ServletJSP JSP或servlet中中文乱码的解决方案: 1.以POST请求方式: 在获取请求参数之前设置: request.setCharacterEncoding("utf-8"); 设置输出编码: response.setContentType("text/html;charse

JS读写cookie以及中文乱码解决

本文地址:http://www.cnblogs.com/PiaoMiaoGongZi/p/4092489.html 转载请注明. Js获取所有的cookie信息: var cookiename = document.cookie.split(";"); Js读写cookie值是中文乱码解决办法: //写入cookie function SetCookie(name, value) { var exp = new Date(); exp.setTime(exp.getTime() + 6

外部调用JS文件时出现中文乱码的解决办法

若测试网页的编码格式为:gb2312,而调用外部JS文件时出现了乱码(前提是JS文件无错误),则将调用的外部JS文件用记事本打开,然后再保存成编码格式为UTF-8的JS文件即可. 若测试网页的编码格式为:UTF-8,则反之即可.

前台传参到后台出现中文乱码问题

方法一:在xml文件中添加字符集过滤 SpringEncodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceEncoding true SpringEncodingFilter /* 方法二:在代码中转换格式 key为前台传过来的参数 String str = new String(key.getBytes("iso-8859-1"),"UTF-8&quo