如今咱們的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