通过尝试设置以下参数,提交到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; }
原文链接:https://www.f2er.com/ajax/165652.html