自定義servlet重寫doGet或者doPost方法時,405 method not allowed
阿新 • • 發佈:2018-12-13
error with 定義 div proto exce eth msg per
自定義servlet
public class TestServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { super.doGet(req, resp); } }
HttpServlet裏的doGet方法是這樣定義的
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String protocol = req.getProtocol(); String msg = lStrings.getString("http.method_get_not_supported"); if (protocol.endsWith("1.1")) { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, msg); } else { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, msg); } }
所以重寫doGet/doPost方法時,必須先將super.doGet(...)/super.doPost(...)刪掉
自定義servlet重寫doGet或者doPost方法時,405 method not allowed