I think you need to delete @ResponseBody, if you want to either edit the answer yourself, or redirect to a single controller method based on some condition, try the following:
@RequestMapping(method = RequestMethod.GET) //remove @ResponseBody public String ABC(Registratio registration, ModelMap modelMap, HttpServletRequest request,HttpServletResponse response){ if(somecondition=="false"){ // here i am returning only the string // in this case, render response yourself and just return null response.getWriter().write("notok"); return null; }else{ // redirect return "redirect:checkPage"; } }
- edit -
if you want to access the controller via ajax, you'd better specify the data type parameter in the request to indicate that you are just waiting for a text response:
$.get("/AAA-Web/abc",jQuery.param({}) ,function(data){ alert(data); }, "text");
Septem
source share