Example #1
0
  public void controller(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    try {

      hsession = HibernateUtil.currentSession();
      sessione = request.getSession();
      tx = hsession.beginTransaction();

      String action = request.getParameter("action");

      if (action == null) action = "home";

      /*if(action.equals("login"))
      login(request, response);*/

      Users u = (Users) sessione.getAttribute("user");

      if (u == null) {
        throw new LoginException();
      } else if (u.getTipo().intValue() < 2) {
        throw new LoginException();
      }

      if (action.equals("home")) accedi(request, response);
      else if (action.equals("chiudi")) chiudiBilancio(request, response);

    } catch (LoginException e) {

      Avviso err = new Avviso(e.getMessage());
      request.setAttribute("err", err);
      nextview = "/./error.jsp";

    } catch (Exception e) {

      Avviso err =
          new Avviso("Errore indefinito. Ricorda di non usare il tasto REFRESH di Explorer!");
      request.setAttribute("err", err);
      System.out.println(e.getMessage());
      nextview = "/./error.jsp";

    } finally {

      RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(nextview);
      if (dispatcher != null) {
        response.encodeURL(nextview);
        dispatcher.forward(request, response);
      }
      HibernateUtil.closeSession();
    }
  }
Example #2
0
  private void accedi(HttpServletRequest request, HttpServletResponse response) {

    Query q = hsession.createQuery("FROM Anno ORDER BY anno");
    request.setAttribute("listaanni", q.list());

    nextview = "/bilancio/home.jsp";
  }