【发布时间】:2018-06-26 07:29:46
【问题描述】:
我希望我的 ajax 调用点击 Spring mvc controller 并返回 jsp view
我已经编写了以下代码来做到这一点
$(document).on("click","#loginSubmit",function(event){
var userName=$("#userName").val();
var pwd=$("#password").val();
var url = contextPath+"/authenticate";
$.ajax({
url : url,
type:"get",
data:"&userName="+userName+"&pwd="+pwd,
contentType:'application/json; charset=utf-8',
async: false,
success:function(response)
{
console.log(response);
}
});
});
这是我的控制器
@RequestMapping(value="/authenticate")
@ResponseBody
public ModelAndView dashboard(@RequestParam("userName") String username,@RequestParam("pwd") String pwd) throws IOException
{
boolean res=false;
try {
res=service.authenticate(username,pwd);
}
catch (Exception e) {
e.printStackTrace();
}
if(res =true)
{
return new ModelAndView("dashboard");
}
else {
return new ModelAndView("login");
}
}
当我点击提交时,它返回 jsp 代码而不是 jsp 视图。
怎么办,我的代码不正确吗?
【问题讨论】:
标签: spring-mvc jsp