I m trying to redirect control to next jsp page. If the boolean value is true redirect to success jsp page else redirect to login page.

```
@RequestMapping(value = "/validate", method = RequestMethod.POST)
@ResponseBody
public ModelAndView(HttpServletRequest request, HttpServletResponse response, Model model) {
    String userName = request.getParameter("userName");
    String password = request.getParameter("password");
    boolean validuser=employeeService.checkLogin(userName,password);
    if(validuser == true)
    {
        model.setViewName("success");
        return model;
    }
    model.setViewName("login");
    return model;
}

```

This is my Ajax call.

```
 $(document).ready(function() {
      $("form").submit(function() {
         var userName=$("#inputEmail").val();
         var password=$("#inputPassword").val();
            $.ajax({
                type : "post",
                url : "${pageContext.request.contextPath}/validate",
                data : {userName:userName, password:password},
                success:function(data){
                    alert(data);        
                },
                error:function()
                {
                    alert("Error ");
                }        
                }); 
      });
    });

```

Control is not going to success block. Only the error alert is getting displayed.

```
public String validate(HttpServletRequest request, HttpServletResponse response, Model model) {
    String userName = request.getParameter("userName");
    String password = request.getParameter("password");
    boolean validuser=employeeService.checkLogin(userName,password);

    if(validuser == true)
    {
        return "redirect:/success";
    }
    else{
    return "redirect:/login";
    }
}

```

I have tried it using this approach. Still its entering error block.