public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {
    String amount = request.getParameter("amount");
    String amount2 = request.getParameter("amount2");
    String amount3 = request.getParameter("amount3");
    Integer posotita = Integer.parseInt(amount);
    Integer posotita2 = Integer.parseInt(amount2);
    Integer posotita3 = Integer.parseInt(amount3);

    HttpSession session = request.getSession();

    if (session.isNew()) {
      request.setAttribute("sessionVal", "this is a new session");
    } else {
      request.setAttribute("sessionVal", "Welcome Back!");
    }

    double total = ((posotita * 18.50) + (posotita2 * 6.95) + (posotita3 * 1.29));
    session.setAttribute("totalVal", total);

    request.setAttribute("currency", total);
    request.setAttribute("from", amount);
    request.setAttribute("from2", amount2);
    request.setAttribute("from3", amount3);

    RequestDispatcher view = request.getRequestDispatcher("index.jsp");
    view.forward(request, response);
  }
 private void setDefaultSchema(HttpServletRequest request) {
   String hibernateDefaultSchemaTab =
       (String) request.getSession().getAttribute("xava_hibernateDefaultSchemaTab");
   if (hibernateDefaultSchemaTab != null) {
     request.getSession().removeAttribute("xava_hibernateDefaultSchemaTab");
     XHibernate.setDefaultSchema(hibernateDefaultSchemaTab);
   }
   String jpaDefaultSchemaTab =
       (String) request.getSession().getAttribute("xava_jpaDefaultSchemaTab");
   if (jpaDefaultSchemaTab != null) {
     request.getSession().removeAttribute("xava_jpaDefaultSchemaTab");
     XPersistence.setDefaultSchema(jpaDefaultSchemaTab);
   }
 }
Пример #3
0
 private void getPositions(HttpServletRequest request, Role item) {
   String[] pos = request.getParameterValues("positions");
   item.clearPositions();
   for (int i = 0; i < pos.length; i++) {
     item.addPosition(Long.parseLong(pos[i]));
   }
 }
Пример #4
0
 private void getPermissions(HttpServletRequest request, Role item) {
   String[] per = request.getParameterValues("permissions");
   item.clearPermissions();
   for (int i = 0; i < per.length; i++) {
     item.addPermission(Long.parseLong(per[i]));
   }
 }
Пример #5
0
  // Process the request
  private String processRequest(HttpServletRequest request, HttpServletResponse response) {
    HttpSession session = request.getSession();
    String userIDs = (String) session.getAttribute("user.id");
    userIDs = (userIDs != null && userIDs.compareTo(" ") > 0) ? userIDs : "0";
    long userID = Long.parseLong(userIDs);
    String command = request.getParameter("command");
    String template = request.getParameter("template");
    String pageHash = request.getParameter("pagehash");
    String pageTitle = request.getParameter("pagetitle");
    String pageDescription = request.getParameter("pagedescription");

    String outLine = "";
    String nextScript = request.getParameter("nextscript");
    OutputStream toClient;
    boolean success = false;

    // System.out.println("userid=" + userID + ", id=" + id + ", command=" + command);

    command = (command != null && command.compareTo(" ") > 0) ? command : "form";
    nextScript = (nextScript != null && nextScript.compareTo(" ") > 0) ? nextScript : "simple1.jsp";

    //    inputstring = (inputstring != null && inputstring.compareTo(" ") > 0) ? inputstring : "";

    DbConn myConn = null;
    try {

      Context initCtx = new InitialContext();
      // String csiSchema = (String) initCtx.lookup("java:comp/env/csi-schema-path");
      // String acronym = (String) initCtx.lookup("java:comp/env/SystemAcronym");
      myConn = new DbConn();
      String csiSchema = myConn.getSchemaPath();
      if (userID != 0) {
        if (command.equals("add")) {
          outLine = "";
        } else if (command.equals("update")) {
          outLine = "";
        } else if (command.equals("updatepage")) {
          UHash uPage = new UHash(pageHash, myConn);
          // System.out.println("Got Here 1");
          if (template.equals("simple1")) {
            TextItem title = new TextItem(uPage.get("title"), myConn);
            title.setText(pageTitle);
            title.save(myConn);
            TextItem description = new TextItem(uPage.get("description"), myConn);
            description.setText(pageDescription);
            description.save(myConn);
          } else if (template.equals("simple2")) {
          }

        } else if (command.equals("test")) {
          outLine = "test";
        }
        success = true;
      }

    } catch (IllegalArgumentException e) {
      outLine = outLine + "IllegalArgumentException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
      // log(outLine);
    } catch (NullPointerException e) {
      outLine = outLine + "NullPointerException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
      // log(outLine);
    }

    // catch (IOException e) {
    //    outLine = outLine + "IOException caught: " + e.getMessage();
    //    ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
    //    //log(outLine);
    // }

    catch (Exception e) {
      outLine = outLine + "Exception caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, pageHash + " error: '" + outLine + "'");
      // log(outLine);
    } finally {
      try {
        generateResponse(outLine, command, nextScript, success, response);
      } catch (Exception i) {
      }

      myConn.release();
      // log("Test log message\n");
    }

    return outLine;
  }
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    try {
      Locales.setCurrent(request);
      if (Users.getCurrent() == null) { // for a bug in websphere portal 5.1 with Domino LDAP
        Users.setCurrent((String) request.getSession().getAttribute("xava.user"));
      }
      request.getParameter("application"); // for a bug in websphere 5.1
      request.getParameter("module"); // for a bug in websphere 5.1
      Tab tab = (Tab) request.getSession().getAttribute("xava_reportTab");
      int[] selectedRowsNumber =
          (int[]) request.getSession().getAttribute("xava_selectedRowsReportTab");
      Map[] selectedKeys = (Map[]) request.getSession().getAttribute("xava_selectedKeysReportTab");
      int[] selectedRows = getSelectedRows(selectedRowsNumber, selectedKeys, tab);
      request.getSession().removeAttribute("xava_selectedRowsReportTab");
      Integer columnCountLimit =
          (Integer) request.getSession().getAttribute("xava_columnCountLimitReportTab");
      request.getSession().removeAttribute("xava_columnCountLimitReportTab");

      setDefaultSchema(request);
      String user = (String) request.getSession().getAttribute("xava_user");
      request.getSession().removeAttribute("xava_user");
      Users.setCurrent(user);
      String uri = request.getRequestURI();
      if (uri.endsWith(".pdf")) {
        InputStream is;
        JRDataSource ds;
        Map parameters = new HashMap();
        synchronized (tab) {
          tab.setRequest(request);
          parameters.put("Title", tab.getTitle());
          parameters.put("Organization", getOrganization());
          parameters.put("Date", getCurrentDate());
          for (String totalProperty : tab.getTotalPropertiesNames()) {
            parameters.put(totalProperty + "__TOTAL__", getTotal(request, tab, totalProperty));
          }
          TableModel tableModel = getTableModel(request, tab, selectedRows, false, true, null);
          tableModel.getValueAt(0, 0);
          if (tableModel.getRowCount() == 0) {
            generateNoRowsPage(response);
            return;
          }
          is = getReport(request, response, tab, tableModel, columnCountLimit);
          ds = new JRTableModelDataSource(tableModel);
        }
        JasperPrint jprint = JasperFillManager.fillReport(is, parameters, ds);
        response.setContentType("application/pdf");
        response.setHeader(
            "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".pdf\"");
        JasperExportManager.exportReportToPdfStream(jprint, response.getOutputStream());
      } else if (uri.endsWith(".csv")) {
        String csvEncoding = XavaPreferences.getInstance().getCSVEncoding();
        if (!Is.emptyString(csvEncoding)) {
          response.setCharacterEncoding(csvEncoding);
        }
        response.setContentType("text/x-csv");
        response.setHeader(
            "Content-Disposition", "inline; filename=\"" + getFileName(tab) + ".csv\"");
        synchronized (tab) {
          tab.setRequest(request);
          response
              .getWriter()
              .print(
                  TableModels.toCSV(
                      getTableModel(request, tab, selectedRows, true, false, columnCountLimit)));
        }
      } else {
        throw new ServletException(
            XavaResources.getString("report_type_not_supported", "", ".pdf .csv"));
      }
    } catch (Exception ex) {
      log.error(ex.getMessage(), ex);
      throw new ServletException(XavaResources.getString("report_error"));
    } finally {
      request.getSession().removeAttribute("xava_reportTab");
    }
  }
Пример #7
0
  // Process the request
  private String processRequest(HttpServletRequest request, HttpServletResponse response) {
    String command = request.getParameter("command");
    String id = request.getParameter("id");
    String description = request.getParameter("description");
    String status = request.getParameter("rstatus");
    status = (status != null && status.compareTo(" ") > 0) ? status : null;
    String outLine = "";
    // String nextScript = "home.jsp";
    String nextScript = request.getParameter("nextscript");
    OutputStream toClient;
    HttpSession session = request.getSession();
    boolean success = false;
    String userIDs = (String) session.getAttribute("user.id");
    long userID = Long.parseLong(userIDs);

    command = (command != null && command.compareTo(" ") > 0) ? command : "form";
    nextScript = (nextScript != null && nextScript.compareTo(" ") > 0) ? nextScript : "roles.jsp";

    //    inputstring = (inputstring != null && inputstring.compareTo(" ") > 0) ? inputstring : "";

    DbConn myConn = null;
    try {

      Context initCtx = new InitialContext();
      // String csiSchema = (String) initCtx.lookup("java:comp/env/csi-schema-path");
      String acronym = (String) initCtx.lookup("java:comp/env/SystemAcronym");
      myConn = new DbConn();
      String csiSchema = myConn.getSchemaPath();
      if (command.equals("add")) {
        Role item = new Role();
        item.setDescription(description);
        item.setStatus(status);
        getPermissions(request, item);
        getPositions(request, item);
        item.add(myConn, userID);
        GlobalMembership.refresh(myConn);
        success = true;
        outLine = "";

      } else if (command.equals("update")) {
        Role item = new Role(myConn, Long.parseLong(id));
        item.setDescription(description);
        item.setStatus(status);
        getPermissions(request, item);
        getPositions(request, item);
        item.save(myConn, userID);
        GlobalMembership.refresh(myConn);
        success = true;
        outLine = "";
      } else if (command.equals("drop")) {
        Role item = new Role(myConn, Long.parseLong(id));
        item.drop(myConn, userID);
        success = true;
        outLine = "Role " + item.getDescription() + " Removed";
      } else if (command.equals("test")) {
        outLine = "test";
      }

    } catch (IllegalArgumentException e) {
      outLine = outLine + "IllegalArgumentException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    } catch (NullPointerException e) {
      outLine = outLine + "NullPointerException caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    }

    // catch (IOException e) {
    //    outLine = outLine + "IOException caught: " + e.getMessage();
    //    ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
    //    //log(outLine);
    // }

    catch (Exception e) {
      outLine = outLine + "Exception caught: " + e.getMessage();
      ALog.logActivity(userID, "csi", 0, "Role error: '" + outLine + "'");
      // log(outLine);
    } finally {
      try {
        generateResponse(outLine, command, nextScript, success, response);
      } catch (Exception i) {
      }

      myConn.release();
      // log("Test log message\n");
    }

    return outLine;
  }