加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

AJAX提交中文乱码 问题

发布时间:2020-12-16 00:50:06 所属栏目:百科 来源:网络整理
导读:通过尝试设置以下参数,提交到struts2 不会乱码: type:"POST", contentType: "application/x-www-form-urlencoded", data: {'title':title,'info':info,'vCode':vCode}, action里直接request.getparamater()方式取,以下提供一个封装参数到map的方法: publ

通过尝试设置以下参数,提交到struts2 不会乱码:

type:"POST",
contentType: "application/x-www-form-urlencoded",

data: {'title':title,'info':info,'vCode':vCode},

action里直接request.getparamater()方式取,以下提供一个封装参数到map的方法:

public static Map<String,String> getParameterMap(HttpServletRequest request) {
Map<String,String> result = new HashMap<String,String>();
Enumeration<String> pNames = request.getParameterNames();
while (pNames.hasMoreElements()) {
// parameter names
String pName = (String) pNames.nextElement();
String newName = pName;
if (pName.startsWith("paramMap.")) {
newName = newName.substring(newName.lastIndexOf('.') + 1);
}

// parameter values String[] pValues = request.getParameterValues(pName); if (pValues.length > 1) { result.put(newName,StringUtils.join(pValues,",")); } else { result.put(newName,request.getParameter(pName)); } } return result; }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读