public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
      throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;

    String contextURI = req.getServletPath();
    MVCController controller = controllers.get(contextURI);
    if (controller != null) {
      MVCModel model = controller.execute(req);

      req.setAttribute("model", model.getData());

      ServletContext context = req.getServletContext();
      RequestDispatcher requestDispacher = context.getRequestDispatcher(model.getViewName());
      requestDispacher.forward(req, resp);
    } else filterChain.doFilter(request, response);
  }
예제 #2
0
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
      throws IOException, ServletException {

    HttpServletRequest req = (HttpServletRequest) request;
    HttpServletResponse resp = (HttpServletResponse) response;

    String contextURI = req.getServletPath();
    MVCController controller = controllers.get(contextURI);
    if (controller != null) {
      MVCModel model = controller.processRequest(req);

      if (model.getJspName().startsWith("redirect:")) {
        controller = controllers.get(model.getJspName().replace("redirect:", ""));
        model = controller.processRequest(req);
        req.setAttribute("model", model.getData());
      } else {
        req.setAttribute("model", model.getData());
      }

      ServletContext context = req.getServletContext();
      RequestDispatcher requestDispacher = context.getRequestDispatcher(model.getJspName());
      requestDispacher.forward(req, resp);
    } else filterChain.doFilter(request, response);
  }