此URL不支持Http方法POST
运行项目提示此信息,查看网上诸多解决方法发现没有我这条,所以记录一下提供一种新的解决方案。
我的问题出现在这条代码中
public class LoginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("123");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.doPost(req, resp);
}
}
这里我们需要将super.doPost(req, resp)中的super.doPost改为doGet就可以正常运行了
public class LoginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
System.out.println("123");
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
{
doGet(req, resp);
}
}