Solucionado (ver solução)
Solucionado
(ver solução)
8
respostas

Página contato 404

Executo o comando mvn jetty:run, tento abrir a página contato, me retorna 404.

8 respostas

ContatoServlet

package br.com.alura.maven.lojaweb;

import java.io.IOException;
import java.io.PrintWriter;

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

@WebServlet(urlPatterns={"/contato"})
public class ContatoServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PrintWriter writer = resp.getWriter();
        writer.println("<html><h2>Entre em Contato</h2></html>");
        writer.close();

    }

}

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>br.com.alura.maven</groupId>
    <artifactId>lojaweb</artifactId>
    <packaging>war</packaging>
    <version>1.0.0-SNAPSHOT</version>
    <name>lojaweb Maven Webapp</name>
    <url>http://maven.apache.org</url>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>lojaweb</finalName>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.3.7.v20160115</version>
            </plugin>
        </plugins>
    </build>
</project>

Percebi que nada está sendo compilado.

C:\Users\Biaggio\workspace\lojaweb>mvn jetty:run
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building lojaweb Maven Webapp 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> jetty-maven-plugin:9.3.7.v20160115:run (default-cli) > test-compile @
 lojaweb >>>
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ lojaweb --
-
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ lojaweb ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ lo
jaweb ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\Biaggio\workspace\lojaweb\sr
c\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ lojaweb
 ---
[INFO] No sources to compile
[INFO]
[INFO] <<< jetty-maven-plugin:9.3.7.v20160115:run (default-cli) < test-compile @
 lojaweb <<<
[INFO]
[INFO]
[INFO] --- jetty-maven-plugin:9.3.7.v20160115:run (default-cli) @ lojaweb ---
[INFO] Configuring Jetty for project: lojaweb Maven Webapp
[INFO] webAppSourceDirectory not set. Trying src\main\webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = C:\Users\Biaggio\workspace\lojaweb\target\classes
[INFO] Logging initialized @5509ms
[INFO] Context path = /
[INFO] Tmp directory = C:\Users\Biaggio\workspace\lojaweb\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = file:///C:/Users/Biaggio/workspace/lojaweb/src/main/webapp
/WEB-INF/web.xml
[INFO] Webapp directory = C:\Users\Biaggio\workspace\lojaweb\src\main\webapp
[INFO] jetty-9.3.7.v20160115
[INFO] Started o.e.j.m.p.JettyWebAppContext@1473b8c0{/,file:///C:/Users/Biaggio/
workspace/lojaweb/src/main/webapp/,AVAILABLE}{file:///C:/Users/Biaggio/workspace
/lojaweb/src/main/webapp/}
[INFO] Started ServerConnector@e04ccf8{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
[INFO] Started @7440ms
[INFO] Started Jetty Server

Boa noite Rodrigo, qual link está usando para a acessar a servlet?

Segue o link

http://localhost:8080/contato

localhost:8080 abre o site o jetty ?

Sim... Quando digito o localhost:8080 tenho o retorno do meu index.jsp.

insira seu código aqui
solução!

Descobri o que era Guilherme, vacilo meu. Esqueci de alterar o web.xml para a versão que estou usando da API, 3.1. Estava a 2.3. Eu alterei e funcionou.

==========================
<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
</web-app>
==========================
Nova
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">
</web-app>

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software