HTTP Error Status 405 Servlet

Asked

Viewed 1,126 times

0

I’ve been doing the "5.5 First Servlet" exercise of the Caelum FJ21 Java Web booklet, "http://localhost:8080/fj21-agenda/oi" to access the page occurs error:

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>

1 answer

2


Just remove the call to the super class:

super.service(request, response);

When you override the service method, everything you need has to be inside your override, it is not necessary to pass the call to the default service method HttpServlet.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.