servlet中 HTTP method GET is not supported by this URL解決方法

練習servlet,重寫service方法時,出現了400錯誤,無法調用service()方法

type Status report

message HTTP method GET is not supported by this URL

description The request sent by the client was syntactically incorrect (HTTP method GET is not supported by this URL).


網上查找的原因如下:

1. 繼承自HttpServlet的Servlet沒有重寫對於請求和響應的處理方法:doGet或doPost等方法;默認調用父類的doGet或doPost等方法;

2. 父類HttpServlet的doGet或doPost等方法覆蓋了你重寫的doGet或doPost等方法;


解決方法:

1. 子類重寫doGet或doPost等方法;

2. 在你擴展的Servlert中重寫doGet或doPost等方法來處理請求和響應時 不要調用父類HttpServlet的doGet或         doPost等方法,即去掉super.doGet(request, response)和super.doPost(request, response); 


不過並沒有解決問題,最後仔細看了下是重寫service(HttpServletResponse response,HttpServletRequest request)方法時,參數順序寫錯了。。

改成service(HttpServletRequest request,HttpServletResponse response)即解決錯誤問題。

ps:方法參數順序不同也算重載。。


發佈了4 篇原創文章 · 獲贊 1 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章