1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
public class ControllerServlet extends HttpServlet
{
Hashtable actions;
public void init() throws ServletException
{
initActions();
}
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException
{
doPost(req,resp);
}
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,IOException
{
// Recupération de l'action
String actionName = req.getParameter("action");
if(actionName == null)
{
resp.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE);
return;
}
// Instanciation de l'action à effectuer
Action action = (Action) actions.get(actionName);
if(action == null)
{
resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
return;
}
// Lancement de l'action
action.perform(this, req, resp);
}
private void initActions()
// Table de hashage comprenant toutes les actions à effectuer
// Chacune de ces actions implémente l'interface Action
{
actions = new Hashtable();
actions.put("authenticate",new AuthenticateAction());
actions.put("logout",new LogoutAction());
actions.put("login",new LoginAction());
actions.put("indexation",new IndexationAction());
}
} |