I’m trying to send back an HTTP coded with some HTML. I get “the method sendStatus(int, String) is undefined for the type HttpServletResponse” error. I also tried with only the code. If I use sendError() instead, then the HTML is not sent.
<%@page contentType="text/html; charset=utf-8" %>
<%@ page isErrorPage = "true"%>
<%response.sendStatus(500, "TEST 500 ERROR WITH HTML PAGE");%>
<html>
<body>
<h1>
Test HTTP Error: 500 ERROR with HTML page
</h1>
</body>
</html>
I’m getting:
ERROR_500_subjectdoc_htmlheader_error_realhtmlerrorpage.jsp:3:12: The method sendStatus(int, String) is undefined for the type HttpServletResponse
<%response.sendStatus(500, "TEST 500 ERROR WITH HTML PAGE");%>
Did you mean the deprecated
setStatusmethod instead? Or perhapssendError? The error message is pretty clear – there’s no such method assendStatus(int, String), and the documentation confirms this.Do you really need to set a message with the status though? Any reason not to just use
setStatus(500)?