Java 返回新模型和视图不起作用
我的控制器:Java 返回新模型和视图不起作用,java,ajax,spring,spring-mvc,Java,Ajax,Spring,Spring Mvc,我的控制器: @RequestMapping(value="/testAdmin", method = RequestMethod.POST,consumes = "application/json") public ModelAndView testAdmin(@RequestBody Student student) { System.out.println(student.getName()+" "+student.getId()+" "+student.getLogin()+"
@RequestMapping(value="/testAdmin", method = RequestMethod.POST,consumes = "application/json")
public ModelAndView testAdmin(@RequestBody Student student) {
System.out.println(student.getName()+" "+student.getId()+" "+student.getLogin()+" "+student.getPassword());
return new ModelAndView("showString","student",student.getName());
}
我的ajax功能:
function test2(a,ob) {
var student={
id:ob[a].id,
login:ob[a].login,
password:ob[a].password,
name:ob[a].name
}
$.ajax({
type: "POST",
contentType : 'application/json; charset=utf-8',
url: "testAdmin",
data: JSON.stringify(student),
success: function (response)
{
alert("success");
},
error : function(xhr, status, errorThrown) {
alert(status+" "+errorThrown.toString());
}
});
}
控制器方法可以工作,但不会转到其他页面。
我不知道如何修复它,请给出一个示例或信息阅读欢迎使用StackOverflow。您提到重定向到新页面不起作用。是否有可以发布的服务器端堆栈跟踪?您能提供的关于错误的任何信息都会很有帮助。@richie我发现控制器只向ajax函数返回html代码,我发出了警报(responce),并看到了一个html代码