package clases; import jakarta.servlet.ServletConfig; 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; import acciones.Accion; import acciones.InsertarUsuario; /** * Servlet implementation class Control */ public class Control extends HttpServlet { private static final long serialVersionUID = 1L; private Hashtable acciones; //Tabla hash public static final String PARAM_ACTION_ID = "ID_ACCION"; /** * @see HttpServlet#HttpServlet() */ public Control() { super(); // TODO Auto-generated constructor stub } @Override public void init(ServletConfig config) throws ServletException { // TODO Auto-generated method stub super.init(config); this.acciones = new Hashtable();//Tabla de acciones this.acciones.put("INSERTAR_USUARIO", new InsertarUsuario());//insertamos accion en tabla hash } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String jsp = "index.jps"; String paramIdAccion = request.getParameter(Control.PARAM_ACTION_ID);//recibimos como parametro el ID de accion Accion accion = this.acciones.get(paramIdAccion);//Obtenemos la accion a realizar de la tabla hash jsp = accion.ejecutar(request, response);//Nos devuelve la JSP a la que hay que ir para realizar la acción request.getRequestDispatcher(jsp).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); } }