jsp中ajax请求
如
function save() {
$.ajax({
//ajax的提交地址
url:'user/login.action',
type:"get",
data:{
username:$("#username").val(),
password:$("#password").val()
},
success: function(d){
window.location.href="user/home.action";
}
});
}
和controller层的页面跳转
@RequestMapping("/login.action")
public String login(HttpServletRequest request) {
String username = request.getParameter("username");
String password = request.getParameter("password");
System.out.println(username);
System.out.println(password);
if (username != null && password != null) {
return "user";
}
return "error";
}
有ajax的时候不支持视图解析器的页面跳转也就是不能走spring.xml中的视图解析器,不能识别返回的user
ajax做的页面提交只能在ajax方法的success属性里面做。如下
window.location.href="user/home.action";