首页 > 代码库 > js传后台action中文乱码处理

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;


本文出自 “学习,总归要学” 博客,请务必保留此出处http://phzg03.blog.51cto.com/5570214/1572148

js传后台action中文乱码处理