×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Nhan Tran
Added: Aug 7, 2021 1:05 PM
Views: 3651
Tags: no tags
  1.   //Filter nay la de dung cho viec dinh huong cho ung dung
  2.         HttpServletRequest req = (HttpServletRequest) request;
  3.         String uri = req.getRequestURI();
  4.         try {
  5.             //filter dispatcher
  6.             int lastIndex = uri.lastIndexOf("/");
  7.             String resource = uri.substring(lastIndex + 1);
  8.             ServletContext context = request.getServletContext();
  9.             Map<String, String> siteMap = (Map<String, String>) context.getAttribute("SITEMAP");
  10.             String url = siteMap.get(resource);
  11.             if (url == null) {
  12.                 url = "error.jsp";
  13.             }
  14.             RequestDispatcher rd = request.getRequestDispatcher(url);
  15.             rd.forward(request, response);
  16.         } catch (IOException | ServletException e) {
  17.             e.printStackTrace();
  18.         }