package MyServlet;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.io.IOException;
/**
* Created by 1192126986 on 2017/1/16.
*/
@WebServlet(name = "showStatus")
public class showStatus extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//设置状态吗和信息,发送给客户端
response.sendError(407,"Need authentication!!!");
}
}
servlet_11 HTTP状态码实例
最新推荐文章于 2022-08-16 14:26:58 发布
本文介绍了一个简单的Servlet示例,该示例通过发送HTTP 407错误响应来请求客户端进行身份验证。代码展示了如何使用doGet方法设置特定的状态码及消息。
1621

被折叠的 条评论
为什么被折叠?



