Страницы

Поиск по вопросам

понедельник, 6 января 2020 г.

Простой сервлет HTTP Status 405 - HTTP method GET is not supported by this URL

#java #servlet


Здравствуйте,код сервлета:

package arver;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by 35717 on 30.03.2016.
 */
public class MainServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException {
        super.doGet(req, resp);
        PrintWriter out = resp.getWriter();
        out.print("servlet");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException {
        super.doPost(req, resp);
    }
}


Файл web.xml

 
    

        
            MainServlet
            arver.MainServlet
        

        
            MainServlet
            /
        

    


структура папок:



ответ сервера:


  HTTP Status 405 - HTTP method GET is not supported by this URL
  
  type Status report
  
  message HTTP method GET is not supported by this URL
  
  description The specified HTTP method is not allowed for the requested
  resource.
  
  Apache Tomcat/9.0.0.M4

    


Ответы

Ответ 1



Может кому поможет: in your doGet() method, get rid of super.doGet(req, resp); The HttpServlet basically follows the template method pattern where all non-overridden HTTP methods returns a HTTP 405 error "Method not supported". When you override such a method, you should not call super method, because you would otherwise still get the HTTP 405 error. The same story goes on for your doPost() method.

Комментариев нет:

Отправить комментарий