How to send an error code using JSP to browser?

Following example shows how a 407 error code is sent to the client browser. After this, the browser would show you "Need authentication!!!" message.

      <title>Setting HTTP Status Code</title>
         // Set error code and reason.
         response.sendError(407, "Need authentication!!!" );

You will receive the following output −

HTTP Status 407 - Need authentication!!!

type Status report

message Need authentication!!!

description The client must first authenticate itself with the proxy (Need authentication!!!).

Apache Tomcat/5.5.29