コード例 #1
0
ファイル: ConfigController.java プロジェクト: ukanabar/CASViD
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    Config config = new Config();

    request.setAttribute("strLink", "config");

    String error = "sucess";

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

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

    if (action.equalsIgnoreCase("search")) {

      List<Config> configs = new ArrayList<Config>();
      configs = dao.getAllConfigs(search);

      if (!configs.isEmpty()) {
        request.setAttribute("configs", configs);
      } else {
        error = "No Configs found!";
      }

    } else {

      config.setConfigParamName(request.getParameter("paramName"));

      config.setConfigParamValue(request.getParameter("paramValue"));

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

      if (configId == null || configId.isEmpty()) {

        dao.addConfig(config);

      } else {

        config.setConfigId(Integer.parseInt(configId));

        dao.updateConfig(config);
      }

      request.setAttribute("configs", dao.getAllConfigs(""));
    }

    request.setAttribute("error", error);

    RequestDispatcher view = request.getRequestDispatcher(LIST_CONFIG);

    view.forward(request, response);
  }
コード例 #2
0
ファイル: Main.java プロジェクト: yttesen24/snake
 public static void main(String[] args) throws IOException {
   Config.init();
   HttpServer server =
       HttpServerFactory.create("http://localhost:" + Config.getServerPort() + "/");
   server.start();
   System.out.println("Server running");
   System.out.println("Visit: http://localhost:" + Config.getServerPort() + "/api");
   Tui.serverMenu();
   System.out.println("Hit return to confirm to stop...");
   System.in.read();
   System.out.println("Stopping server");
   server.stop(0);
   System.out.println("Server stopped");
 }
コード例 #3
0
ファイル: Inicio.java プロジェクト: javierDAW/moodleWiki
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    Long timeIni = System.currentTimeMillis();

    HttpSession sesion = request.getSession();

    try {
      // usuario actual
      Usuario usuario = new Usuario();
      if (sesion.getAttribute("usuario") != null) {
        usuario = (Usuario) sesion.getAttribute("usuario");
      }

      // configuración de paginación
      String path = getServletContext().getRealPath("WEB-INF/config.xml");
      int docsPagina = Config.getInitPages(usuario.getId(), path, "documents");
      sesion.setAttribute("configPath", path);

      // privacidad de los documentos
      String cond = "(PRIVADO = 0 OR (PRIVADO = 1 AND ID_USUARIO = " + usuario.getId() + "))";

      // filtro de búsqueda
      String buscar = request.getParameter("buscar");
      if (buscar != null) {
        if (Convert.isValidDate(buscar)) {
          buscar = Utiles.dateToMySQLDate(Convert.parseDate(buscar), false);
        }

        cond += " AND (TITULO LIKE('%" + buscar + "%') ";
        cond += " OR CONTENIDO LIKE('%" + buscar + "%') ";
        cond += " OR ETIQUETAS LIKE('%" + buscar + "%') ";
        cond += " OR FECHA LIKE ('%" + buscar + "%') ";

        for (Usuario u : new UsuarioDAO().findAllUsuario()) {
          if (u.getNombre().toLowerCase().contains(buscar.toLowerCase())
              || u.getApe1().toLowerCase().contains(buscar.toLowerCase())
              || u.getApe2().toLowerCase().contains(buscar.toLowerCase())) {
            cond += " OR ID_USUARIO = " + u.getId();
          }
        }

        cond += ") ";
      }

      DocumentoDAO documentoDAO = new DocumentoDAO();
      sesion.setAttribute(
          "allDocuments", (ArrayList) documentoDAO.findAllDocumento(docsPagina, cond));

      if (count == 1) {
        sesion.setAttribute("dataMenu", (ArrayList) documentoDAO.findAllDocumento(cond));
        count++;
      }

    } catch (Exception ex) {
      Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
      Long timeEnd = System.currentTimeMillis();
      System.out.println("Duración de procesado " + getServletName() + ": " + (timeEnd - timeIni));
      ServletContext cont = getServletConfig().getServletContext();
      RequestDispatcher reqDispatcher = cont.getRequestDispatcher("/index.jsp");
      reqDispatcher.forward(request, response);
    }
  }