servlet请求重定向问题

请问这段代码 为什么会报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错误表示对于指定资源的请求方法不被允许。

大神问答

你的webconfig配置是调用的你的servlet么?很可能你调用的是父类的的dopost方法,

Servlet中没有doGet()方法
重写一下loginServlet和CookieTest中的doGet()方法,然后在doPost()方法中调用一下doGet()方法就行了

     protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.sendRedirect("CookieTest1");
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

客户端重定向拿不到登录界面的值,建议还是使用请求向下发(服务器内部跳转)只要把第16行的重定向改为
req.getRequestDispatcher("CookieTest1").forward(req, resp)