Browse - Programming Tips - Java: HttpServletRespose.setStatus is deprecated, what should I use instead?

Date: 2019mar8
Language: Java

Q.  Java: HttpServletRespose.setStatus is deprecated, what should I use instead?

A.  Use sendError().

Replace:
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED, "Not Modified");
With:
try { response.sendError(HttpServletResponse.SC_NOT_MODIFIED, "Not Modified"); } catch (IOException ex) { // Handle exception }