HTTP Error Status 405 Servlet

0

I've been doing the "5.5 First Servlet" exercise on Caelum's Java Web FJ21 handout, I made the code, restarted Tomcat as requested but when I open the link "http: // localhost: 8080 / fj21-agenda / oi "> link " to access the page the error occurs:

  

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.

CODES:

public class OiMundo extends HttpServlet {
@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    super.service(request, response);

    PrintWriter out = response.getWriter();

    out.println("<html>");
    out.println("<head>");
    out.println("<title>Primeira Servlet</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("<h1>Oi mundo Servlet!</h1>");
    out.println("</body>");
    out.println("</html>");
}}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>fj21-agenda</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
    <servlet>
    <servlet-name>servletOiMundo</servlet-name>
    <servlet-class>br.com.caelum.servlet.OiMundo</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>servletOiMundo</servlet-name>
    <url-pattern>/oi</url-pattern>
  </servlet-mapping>
</web-app>
    
asked by anonymous 21.05.2017 / 16:35

1 answer

2

Just remove the call to super class:

super.service(request, response);

When you override the service method, everything you need has to be within your override, you do not need to pass the call to the default method of HttpServlet .

    
22.05.2017 / 04:56