servlet中doget dopost方法源码分析

servletdoget dopost方法源码分析

现在我们的javaweb中在网络这一块相比之下get post请求使用的相对较多,下面我将从源码的角度分析这两钟方法:

doget()方法:

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

(1)这里的getProtocol()方法是用来获取客户端向服务器端传递值所依据协议的名称
    String protocol = req.getProtocol();
    String msg = lStrings.getString("http.method_get_not_supported");
    if(protocol.endsWith("1.1")) {
        resp.sendError(405, msg);
    } else {
        resp.sendError(400, msg);
    }

}

在方法中只是写出了一些基本的错误的处理,其中的具体实现比没有写,需要调用时对该方法进行重写。

Dopost();(在dopost方法中也是同doget一样的)

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String protocol = req.getProtocol();
    String msg = lStrings.getString("http.method_post_not_supported");
    if(protocol.endsWith("1.1")) {
        resp.sendError(405, msg);
    } else {
        resp.sendError(400, msg);
    }

}

 


你可能感兴趣的:(servlet中doget dopost方法源码分析)