Exemplo n.º 1
0
  @Override
  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) {
    HttpServletRequest r = (HttpServletRequest) req;

    // Some info
    LOG.log(Level.INFO, "URL={0}", r.getRequestURL());
    LOG.log(Level.INFO, "URI={0}", r.getRequestURI());
    LOG.log(Level.INFO, "SERVLET PATH={0}", r.getServletPath());
    LOG.log(Level.INFO, "PATH INFO={0}", r.getPathInfo());
    LOG.log(Level.INFO, "QUERY={0}", r.getQueryString());
    LOG.log(Level.INFO, "--------------------------");

    String uri = r.getRequestURI();
    String path = r.getServletPath();
    try {
      // Pass through resources
      if (resources.matcher(uri).matches()) {
        chain.doFilter(req, res);
      } else if (path.equals("/") || path.equals("/home")) {
        req.getRequestDispatcher(TEMPLATE + "?partial=home").forward(req, res);
      } else {
        chain.doFilter(req, res);
      }
    } catch (IOException | ServletException ex) {
      LOG.log(Level.WARNING, ex.getMessage());
      try {
        req.setAttribute("error", ex.getMessage());
        req.getRequestDispatcher(TEMPLATE + "?partial=error").forward(req, res);
      } catch (ServletException | IOException ex1) {
        LOG.log(Level.SEVERE, ex1.getMessage());
      }
    }
  }
Exemplo n.º 2
0
 @Override
 public void launchPage(HttpServletRequest request, HttpServletResponse response) {
   this.entries = this.repertoire.listerPersonnes();
   if (this.nameEntry == null) {
     request.setAttribute("email", "");
     request.setAttribute("url", "");
     request.setAttribute("descr", "");
     request.setAttribute("entryName", "No entry selected");
   } else {
     Personne entry = this.repertoire.chercherPersonne(this.nameEntry);
     request.setAttribute("email", entry.getEmail());
     request.setAttribute("url", entry.getUrl());
     request.setAttribute("descr", entry.getInfo());
     request.setAttribute("entryName", this.nameEntry);
   }
   request.setAttribute("entriesSize", this.entries.length);
   request.setAttribute("entryOptions", this.createOptions());
   try {
     this.getServletContext()
         .getRequestDispatcher("/WebPages/RepertoirePage.jsp")
         .forward(request, response);
   } catch (IOException | ServletException e) {
     e
         .printStackTrace(); // TODO write in response that the request did not succeeded and why.
                             // Change the status
   }
 }