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);
    }

}

 

 

转载于:https://my.oschina.net/u/2453842/blog/656276

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值