Error while running Servlet

Asked

Viewed 50 times

-2

While running my project. I received an error message. Tomcant is running and I have a contact class and a contact server.

Code contact

package com.dev;

import java.util.Date;

public class Contato {

    private String nome;
    private String endereço;
    private String email;
    private Date DataNascimento;

    public String getNome() {
        return nome;
    }
    public void setNome(String nome) {
        this.nome = nome;
    }
    public String getEndereço() {
        return endereço;
    }
    public void setEndereço(String endereço) {
        this.endereço = endereço;
    }
    public String getEmail() {
        return email;
    }
    public void setEmail(String email) {
        this.email = email;
    }
    public Date getDataNascimento() {
        return DataNascimento;
    }
    public void setDataNascimento(Date dataNascimento) {
        DataNascimento = dataNascimento;
    }

}

Code Servlet Add contact

package com.dev;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

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


/**
 * Servlet implementation class adicionarContato
 */
@WebServlet("/adicionarContato")
public class adicionarContato extends HttpServlet {
    protected void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
        PrintWriter out = response.getWriter();

        //pegando os valores
        String nome            = request.getParameter("nome");
        String endereco        = request.getParameter("endereco");
        String email           = request.getParameter("email");
        String dataNascimentoT = request.getParameter("dataNascimento");

        Date dataNascimento = null;


        //montagem do objeto
        Contato contato = new Contato();
        contato.setNome(nome);
        contato.setEndereço(endereco);
        contato.setEmail(email);


        //conversao da data
        try {
            dataNascimento = new SimpleDateFormat("dd/mm/YYYY").parse(dataNascimentoT);
        } catch (Exception e) {
            // TODO: handle exception
            out.println("Erro de conversao");
            return;
        }

        contato.setDataNascimento(dataNascimento);

        //imprimir os dados
        out.println("<html>");
        out.println("<body>");

        out.println("Nome: "+contato.getNome()
          +"<br> Endereco: "+contato.getEndereço()
          +"<br> Email:"    +contato.getEmail()
          +"<br> Data:"     +contato.getDataNascimento());

        out.println("</body>");
        out.println("</html>");

    }
}

Error message

ago 22, 2018 7:42:53 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
ADVERTÊNCIA: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:teste01' did not find a matching property.
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server version:        Apache Tomcat/8.5.32
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server built:          Jun 20 2018 19:50:35 UTC
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Server number:         8.5.32.0
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Name:               Windows 10
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: OS Version:            10.0
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Architecture:          amd64
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Java Home:             C:\Program Files\Java\jre1.8.0_181
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Version:           1.8.0_181-b13
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: JVM Vendor:            Oracle Corporation
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_BASE:         C:\Users\RC01\eclipse-workspace\teste1\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: CATALINA_HOME:         C:\Users\RC01\Downloads\apache-tomcat-8.5.32-windows-x64\apache-tomcat-8.5.32
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.base=C:\Users\RC01\eclipse-workspace\teste1\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dcatalina.home=C:\Users\RC01\Downloads\apache-tomcat-8.5.32-windows-x64\apache-tomcat-8.5.32
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dwtp.deploy=C:\Users\RC01\eclipse-workspace\teste1\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Djava.endorsed.dirs=C:\Users\RC01\Downloads\apache-tomcat-8.5.32-windows-x64\apache-tomcat-8.5.32\endorsed
ago 22, 2018 7:42:53 PM org.apache.catalina.startup.VersionLoggerListener log
INFORMAÇÕES: Command line argument: -Dfile.encoding=Cp1252
ago 22, 2018 7:42:53 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFORMAÇÕES: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jre1.8.0_181\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_181/bin/server;C:/Program Files/Java/jre1.8.0_181/bin;C:/Program Files/Java/jre1.8.0_181/lib/amd64;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Python27\;C:\Python27\Scripts;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Python27;C:\Python27\Scripts;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Java\jdk1.8.0_181\bin;;C:\Program Files\Microsoft VS Code\bin;C:\ProgramData\chocolatey\bin;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Users\RC01\AppData\Local\Microsoft\WindowsApps;C:\Users\RC01\AppData\Roaming\Composer\vendor\bin;C:\Program Files\Docker Toolbox;C:\Users\RC01\Desktop;;.]
ago 22, 2018 7:42:55 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["http-nio-8080"]
ago 22, 2018 7:42:55 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAÇÕES: Using a shared selector for servlet write/read
ago 22, 2018 7:42:55 PM org.apache.coyote.AbstractProtocol init
INFORMAÇÕES: Initializing ProtocolHandler ["ajp-nio-8009"]
ago 22, 2018 7:42:55 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFORMAÇÕES: Using a shared selector for servlet write/read
ago 22, 2018 7:42:55 PM org.apache.catalina.startup.Catalina load
INFORMAÇÕES: Initialization processed in 5135 ms
ago 22, 2018 7:42:56 PM org.apache.catalina.core.StandardService startInternal
INFORMAÇÕES: Starting service [Catalina]
ago 22, 2018 7:42:56 PM org.apache.catalina.core.StandardEngine startInternal
INFORMAÇÕES: Starting Servlet Engine: Apache Tomcat/8.5.32
ago 22, 2018 7:43:04 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMAÇÕES: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
ago 22, 2018 7:43:09 PM org.apache.jasper.servlet.TldScanner scanJars
INFORMAÇÕES: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
ago 22, 2018 7:43:09 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["http-nio-8080"]
ago 22, 2018 7:43:09 PM org.apache.coyote.AbstractProtocol start
INFORMAÇÕES: Starting ProtocolHandler ["ajp-nio-8009"]
ago 22, 2018 7:43:09 PM org.apache.catalina.startup.Catalina start
INFORMAÇÕES: Server startup in 13292 ms

error image: inserir a descrição da imagem aqui

1 answer

0


Missing to generate web.xml.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>teste01</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>

Browser other questions tagged

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