方法是HttpServlet的子类重写

时间:2011-07-19 05:39:39

标签: java servlets

我已在HttpServlet文档中读到

HttpServlet的子类必须至少覆盖一个方法,通常是以下方法之一:

doGet, if the servlet supports HTTP GET requests
doPost, for HTTP POST requests
doPut, for HTTP PUT requests
doDelete, for HTTP DELETE requests
init and destroy, to manage resources that are held for the life of the servlet
getServletInfo, which the servlet uses to provide information about itself 

什么规则可以帮助编译器检查上述任何一种方法是否被子类覆盖?

2 个答案:

答案 0 :(得分:3)

无。当您使用非重写的HTTP方法请求servlet时,您(实际上,最终用户)将面临HTTP 405 方法未实现错误,因为这是默认实现的作用。

答案 1 :(得分:0)

所有这些方法都是protected。编译器不能要求子类覆盖“至少其中一个”。

没有意义,因为你会有一个“未实现爆炸”的servlet。