HttpServletResponse response = ...; int statusCode = response.getStatus(); if (statusCode >= 200 && statusCode < 300) { // Success! Continue processing } else { // Error handling }
HttpServletResponse response = ...; response.setStatus(404);Package/library: javax.servlet.http In both examples, we are utilizing the HttpServletResponse class to get/set the status code of the HTTP response. The package/library used is javax.servlet.http.