Search in sources :

Example 1 with UsuarioDAO

use of br.senac.tads3.pi03b.gruposete.dao.UsuarioDAO in project Loja_Agencia_De_Viagens by ArtCouSan.

the class ExcluiUsuarioServlet method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String action = request.getParameter("action");
    String pesquisa = request.getParameter("pesquisa");
    UsuarioDAO query = new UsuarioDAO();
    if ("edit".equalsIgnoreCase(action)) {
        int id = Integer.parseInt(request.getParameter("id"));
        try {
            query.excluirUsuario(id);
            List<Usuario> encontrados = query.procurarUsuario(pesquisa);
            request.setAttribute("encontrados", encontrados);
        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(ExcluiClienteServlet.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(ExcluiUsuarioServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
        RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/Listar/ListaUsuario.jsp");
        dispatcher.forward(request, response);
    }
}
Also used : Usuario(br.senac.tads3.pi03b.gruposete.models.Usuario) SQLException(java.sql.SQLException) UsuarioDAO(br.senac.tads3.pi03b.gruposete.dao.UsuarioDAO) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) SQLException(java.sql.SQLException) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 2 with UsuarioDAO

use of br.senac.tads3.pi03b.gruposete.dao.UsuarioDAO in project Loja_Agencia_De_Viagens by ArtCouSan.

the class CadastroUsuarioServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    UsuarioDAO dao = new UsuarioDAO();
    boolean erro = false;
    String nome = request.getParameter("nome");
    if (nome == null || nome.length() < 1) {
        erro = true;
        request.setAttribute("erroNome", true);
    }
    String login = request.getParameter("login");
    if (login == null || login.length() < 1) {
        erro = true;
        request.setAttribute("erroLogin", true);
    }
    String senha = request.getParameter("senha");
    if (senha == null || senha.length() < 4) {
        erro = true;
        request.setAttribute("erroSenha", true);
    }
    String acesso = request.getParameter("acesso");
    if (acesso == null || acesso.length() < 1) {
        erro = true;
        request.setAttribute("erroAcesso", true);
    }
    if (!erro) {
        Usuario usuarioHumilde = new Usuario(nome, login, senha, acesso);
        try {
            dao.inserir(usuarioHumilde);
            HttpSession sessao = request.getSession();
            sessao.setAttribute("novoUsuario", usuarioHumilde);
            response.sendRedirect("index.jsp");
        } catch (Exception ex) {
            Logger.getLogger(CadastroUsuarioServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/Cadastrar/CadastroUsuario.jsp");
        dispatcher.forward(request, response);
    }
}
Also used : Usuario(br.senac.tads3.pi03b.gruposete.models.Usuario) HttpSession(javax.servlet.http.HttpSession) UsuarioDAO(br.senac.tads3.pi03b.gruposete.dao.UsuarioDAO) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

UsuarioDAO (br.senac.tads3.pi03b.gruposete.dao.UsuarioDAO)2 Usuario (br.senac.tads3.pi03b.gruposete.models.Usuario)2 IOException (java.io.IOException)2 RequestDispatcher (javax.servlet.RequestDispatcher)2 ServletException (javax.servlet.ServletException)2 SQLException (java.sql.SQLException)1 HttpSession (javax.servlet.http.HttpSession)1