1.jsp页面 jsp中添加一个登陆提交按钮 /* ajax登录 */ function login(thisobj){ var username=$("#username_l").val(); var password=$("#password_l").val(); var valistr=$("#valistrId").val(); var user_json = { "username":username, "password":password } var jason_str = JSON.stringify(user_json); //Ajax发送数据给后台 $.ajax({ url :"/login?"+"valistr="+valistr, cache : true, type : "post", datatype : "json", contentType : "application/json; charset=utf-8", data : jason_str, success : function (msg){ if(msg=="0"){ $("#loginf").html("<font color='red'>用户名和密码不能为空</font>"); }else if(msg=="1"){ $("#loginf").html("<font color='red'>用户名或密码不正确</font>"); }else if(msg=="3"){ $("#loginf").html("<font color='red'>验证码不正确</font>"); }else if(msg=="2"){ window.location.href="/index.jsp"; } } }); } 2.controller接受参数 @RequestMapping("/login") @ResponseBody public String login(@RequestBody User u,String valistr,HttpSession session) throws IOException{}........省略