如今咱们的javaweb中在网络这一块相比之下get 和post请求使用的相对较多,下面我将从源码的角度分析这两钟方法:java
doget()方法:web
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同样的)post
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);
}
}spa