ResponseEntity
всегда будет возвращать Object
. В вашем случае String
.
ResponseEntity("index.jsp",HttpStatus.NOT_FOUND);
Для загрузки конкретной страницы JSP вы можете использовать ModelAndView
.
Вы также можете передать дополнительную информацию в ModelView, что может быть удобно.
@ExceptionHandler(Exception.class)
public ModelAndView handleError(HttpServletRequest req, Exception ex) {
ModelAndView mav = new ModelAndView();
mav.addObject("url", req.getRequestURL()); // Can read this in JSP by getting url
mav.setViewName("index"); // calls index.jsp
return mav;
}
Редактировать 1:
mav.setStatus(HttpStatus.NOT_FOUND);