Servlet ---------------------Servlet体系根接口
GenericServlet ----------Servlet抽象实现类
HttpServlet-----------------对HTTP协议封装的Servlet实现类
我们将来开发的B/S架构的web项目,都是针对HTTP协议,所以我们自定义Servlet会继承HttpServlet
Servlet urlPattern配置
@WebServlet(urlPatterns = {"/demo4","/demo5"})
出现HTTP Status 405 - HTTP method GET is not supported by this URL
出现HTTP Status 405 - HTTP method GET is not supported by this URL
原因是:
1、继承自Httpservlet的Servlet没有重写对于请求和响应的处理方法:doGet或doPost等方法,默认调用父类的doGet或doPost等方法。
2、父类HttpServlet的doGet或doPost等方法覆盖了你写的到doGet或doPost等方法。
不管是1或2,父类HttpServlet的doGet或doPost等方法默认实现是返回状态码是405的Http错误表示 对于指定资源请求方法不被允许。
解决方法:
1、子类重写doGet或doPost等方法。
2、在你扩张的Servlet中重写doGet或doPost等方法来处理请求和响应时,不要调用父类的doGet或doPost等方法即去掉supper.doGet(request,response)和super.doPost(request,response);
XML配置Servlet