In my app,I use springMVC and tomcat,my controller return object,but when something wrong,I only want return some string message with content tye json,so I use response.error, but it not work,the return is a html. my controller:
@RequestMapping(value = "{id}/{name}" ,method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody UserBean login(@PathVariable String id,@PathVariable("name") String userName,
@RequestHeader(value = "User-Agent") String user_agen,
@CookieValue(required = false) Cookie userId,
HttpServletRequest request,HttpServletResponse response,@RequestBody UserBean entity
) throws IOException {
System.out.println("dsdsd");
System.out.print(userName);
response.setContentType( MediaType.APPLICATION_JSON_VALUE);
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "somethind wrong");
return null;