Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Lập Trình

Cách gửi error code đến browser bằng JSP

Ví dụ sau minh họa cách gửi error code 407 đến client browser. Sau đó, browser sẽ hiển thị thông báo "Need authentication!!!".

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

Bạn sẽ nhận được output sau:

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