问题出现:
前端页面中表单提交的方法为Post,把servlet代码写在doGet方法内会出现如下的问题:

如何解决:
一开始看网上的解决方案是:
1 2 3 4 5 6 7 8
| protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { }
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { super.doGet(req,resp); }
|
可是写上之后,仍然会出现405错误
发现此时调用的是父类的方法,应该调用本类中的方法
1 2 3 4 5 6 7 8
| protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { }
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { this.doGet(req,resp); }
|
改动之后,问题解决