Ir ao conteúdo
  • Cadastre-se

Java javax.servlet.ServletException: Error instantiating servlet class servlets


Posts recomendados

 Boa noite colegas, 

Estou criando este post, porque infelizmente não consigo acessar meu servlet.

Estou estudando, e fiz tudo de acordo com o material disponibilizado e não passo do index.

Estou usando o Apache Netbeans 12.0, como jdk 11 e o servidor glassfish 5.0.1

 

segue o seguinte erro

 

erro.png.44305624ca12fa6ed4632ee865a10fd9.png

 

 

aqui vem os pacotes no netbeans

434190649_detalhesdoprojeto.png.f60543c2403935d1b81b56cae3481583.png

 

código do index da página

<!DOCTYPE html>
<html>
    <head>
        <title>Cad. Matrícula</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <div>

            <h2>Cadastro de Alunos</h2>
            <form action="MatriculaServlet" method="get">
                Matrícula
                <input type="text" name="id"/>
                Nome
                <input type="text" name="nome"/>
                Idade
                <input type="text" name="idade"/>
                <input type="submit" value="Enviar">

            </form>
        </div>
    </body>
</html>

 

segue a classe do servlet

 

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

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
     * methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        
        String id = request.getParameter("id");
        String nome = request.getParameter("nome");
        String idade = request.getParameter("idade");
        
        response.setContentType("text/html;charset=UTF-8");
        try ( PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet MatriculaServlet</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet MatriculaServlet at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }

 

arquivo do web.xml

 

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0" 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_4_0.xsd">
    <servlet>
        <servlet-name>MatriculaServlet</servlet-name>
        <servlet-class>servlets.MatriculaServlet</servlet-class>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>MatriculaServlet</servlet-name>
        <url-pattern>/MatriculaServlet</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

 

Link para o comentário
Compartilhar em outros sites

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...