Ajax向后台传值和form表单传值有什么区别?该怎么解决

Ajax向后台传值和form表单传值有什么区别?
页面:
<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
</head>
<body>
    
 <script type="text/javascript">
   function AjaxSubmit(){
   var inputCharset=$("#inputCharset").val();
   var username=$("#username").val();
   $.ajax({
                    url:"<%=request.getContextPath()%>/display.action",
                    type:"post",
                   data:{
                       "inputCharset":inputCharset,
                        "username":username
                    },
                contentType:"application/x-www-form-urlencoded;charset=GBK",
   });
 }
 </script>
  <form id="testFrom" name="testForm" action="<%=request.getContextPath()%>/display.action" method="post">
     <table id="testForm_tabel" name="testForm_table" >
      <tr>
       <td>
         <input  type="text" id="inputCharset" name="inputCharset" value="2">
          <input type="text" id="username"  name="username" value="小明">
            
        </td>
      </tr>
     </table>
     <input type="button" id="button1" name="button1" value="提交1" onClick="AjaxSubmit()" />
     <input type="submit" value="提交2" />
   
  </form>
</body>

配置的编码过滤器:
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/WEB-INF/views/*</url-pattern>
</filter-mapping>
后台接收代码:
  public ModelAndView handleRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {

request.setCharacterEncoding("GBK");
Map<String,String> map=new HashMap<String,String>();
String inputCharset=request.getParameter("inputCharset");
String username=request.getParameter("username");
logger.debug("inputCharset is:"+inputCharset);
logger.debug("username is:"+username);
map.put("username", username);
map.put("inputCharset", inputCharset);
ModelAndView model=new ModelAndView("display",map);
return model;
}
现在用Ajax提交后台汉字就输出乱码,直接用form表单提交就正常。
我试了下,把类里边的request.setCharacterEncoding("GBK")这行代码注释掉,Ajax提交就正常了;但是form表单提交又是乱码了,彻底迷糊了,望高手指点迷津。
------解决方案--------------------
request.setCharacterEncoding("GBK");
response.setContentType("text/html;charset=GBK");
String username = new String(request.getParameter("username").getBytes("ISO-8859-1"), "GBK");

AJAX提交时这样试试
------解决方案--------------------
会不会你的编码过滤器问题呢
你的过滤器设置编码为UTF-8,后台又是GBK

不如干脆去掉过滤器试试   或者前台后台都换成UTF-8
------解决方案--------------------
编码不统一,迟早会有乱码的
------解决方案--------------------
ajax提交可以实现异步请求,在页面不刷新的情况下,数据就可以返回过来
但是form提交之后页面会刷新,并获得信息
------解决方案--------------------

String reqHeader = request.getHeader("x-requested-with");
if("XMLHttpRequest".equals(reqHeader )){
req.setCharacterEncoding("UTF-8");
}else{
req.setCharacterEncoding("GBK");
}

------解决方案--------------------
花点功夫吧所有编码统一到UTF8,磨刀不误砍柴工么。