如何使用 JSP 向瀏覽器傳送錯誤程式碼?


以下示例展示如何向客戶端瀏覽器傳送 407 錯誤程式碼。傳送後,瀏覽器將顯示“需要身份驗證!!!”訊息。

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

你將收到以下輸出 −

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

更新日期:2019 年 7 月 30 日

324 閱讀量

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.