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.

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

You will receive the following output −

<p>HTTP Status 407 - Need authentication!!!</p>
<p><strong>type</strong> Status report</p>
<p><strong>message</strong>
<u>Need authentication!!!</u></p>
<p><strong>description</strong>
<u>The client must first authenticate itself with the proxy (Need authentication!!!).</u></p>
<p>Apache Tomcat/5.5.29</p>
Updated on: 2019-07-30T22:30:25+05:30

473 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements