1
resposta

MAPEAMENTO DE SERVLET

Esta aparecendo esse erro quando vou executar a servlet:The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

<?xml version="1.0" encoding="UTF-8"?> 
<web-app >
    <servlet>
      <servlet-name>PrimeiraServlet</servlet-name>
      <servlet-class>Servlets.Ola</servlet-class>
      </servlet>
      <servlet-mapping>
      <servlet-name>PrimeiraServlet</servlet-name>
      <url-patern>/oi</url-patern>
      </servlet-mapping>


      </web-app>
package Servlets;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Ola extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO Auto-generated method stub

        resp.setContentType("text/html");
        PrintWriter writer = resp.getWriter();
        writer.println("<html> <body>");
        writer.println("Primeira Servlet");
        writer.println("</html></body>");

    }


}

insira seu código aqui

1 resposta

Algumas coisas pra tentar:

  1. Verifica se a estrutura de pastas está ok no projeto (WEB-INF etc)

  2. Verifica se o mapeamento no Tomcat ta ok

  3. Coloca o header completo no XML:

<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%20http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
   id="aplicacao" version="3.0">