package com.login.web; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.WebServlet; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.Hashtable; /** * Servlet implementation class InsertarUsuario */ public class InsertarUsuario extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public InsertarUsuario() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub //response.getWriter().append("Served at: ").append(request.getContextPath()); //request.getRequestDispatcher("destino.html").forward(request, response); Hashtable usuarios = (Hashtable) request.getServletContext().getAttribute("TABLAUSUARIOS"); if(usuarios == null) { usuarios = new Hashtable(); request.getServletContext().setAttribute("TABLAUSUARIOS", usuarios); } Usuario usuario = new Usuario(request.getParameter("usuario"),request.getParameter("pass")); usuarios.put(usuario.getUsername(), usuario); System.out.println("Usuarios del sistema" + usuarios.size()); request.getRequestDispatcher("index.html").forward(request, response); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }