예제 #1
0
 protected collegeTable getCollege(String id, Connection con) throws SQLException {
   try {
     ResultSet rs = null;
     Statement statement = con.createStatement();
     rs =
         statement.executeQuery(
             "SELECT * FROM "
                 + TABLECOLLEGES
                 + " WHERE "
                 + collegeTable.ID
                 + " = "
                 + id
                 + " LIMIT 1");
     // if found
     if (rs.next()) {
       collegeTable table = new collegeTable();
       table.setID(id);
       table.setShort(rs.getString(collegeTable.SHORTNAME));
       table.setFull(rs.getString(collegeTable.FULLNAME));
       return table;
     } else {
       return null; // not found
     }
   } catch (Exception e) {
     log.writeException(e.getMessage());
     throw new SQLException(e.getMessage());
   }
 } // end getCollege
예제 #2
0
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   EstacionBombeoModule module = (EstacionBombeoModule) context.getBean("estacionBombeoModule");
   try {
     String presionSalida = request.getParameter("presionSalida");
     int presionSalidaObj = Integer.parseInt(presionSalida);
     String presionEntrada = request.getParameter("presionEntrada");
     int presionEntradaObj = Integer.parseInt(presionEntrada);
     String cantidadBombas = request.getParameter("cantidadBombas");
     int cantidadBombasObj = Integer.parseInt(cantidadBombas);
     String capacidadMaxima = request.getParameter("capacidadMaxima");
     int capacidadMaximaObj = Integer.parseInt(cantidadBombas);
     String idAcueducto = request.getParameter("idAcueducto");
     int idAcueductoObj = Integer.parseInt(idAcueducto);
     String encargado = request.getParameter("encargado");
     String tipo = request.getParameter("tipo");
     String telefono = request.getParameter("telefono");
     String nombreEstacion = request.getParameter("nombreEstacion");
     module.insertar(
         presionSalidaObj,
         tipo,
         capacidadMaximaObj,
         cantidadBombasObj,
         encargado,
         telefono,
         presionEntradaObj,
         idAcueductoObj,
         nombreEstacion);
     response.sendRedirect("listaEstacionBombeos");
   } catch (Exception e) {
     request.setAttribute("mensaje", e.getMessage());
     forward(e.getMessage(), request, response);
   }
 }
예제 #3
0
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    AcueductoModule module = (AcueductoModule) context.getBean("acueductoModule");
    try {
      List data = module.listado();
      request.setAttribute("acueductos", data);
      forward("/listaAcueductos.jsp", request, response);
    } catch (Exception e) {

      request.setAttribute("mensaje", e.getMessage());
      forward(e.getMessage(), request, response);
    }
  }
 /**
  * Permet de repondre a une requete web En affichant la liste des Spectacles et representations :
  * Utiliste JQuery javascript pour la mise en forme
  *
  * @param HttpServletRequest request requete
  * @param HttpServletResponse response reponse
  * @throw IOException, ServletException
  * @return void
  */
 public void doGet(HttpServletRequest req, HttpServletResponse res)
     throws ServletException, IOException {
   // Get the session object
   HttpSession session = req.getSession(true);
   // Get the output stream
   ServletOutputStream out = res.getOutputStream();
   res.setContentType("text/html");
   out.println("<HEAD><TITLE>Reservation de tickets </TITLE></HEAD><BODY>");
   out.println("<h1> Reservations de tickets </h1>");
   out.println("<BODY bgproperties=\"fixed\" background=\"/images/rideau.JPG\">");
   out.println("<p align=\"Right\"><font face=\"Monotype Corsiva\"style=\"font-size: 16pt\">");
   try {
     // Open the file that is the first
     // command line parameter
     String relativeWebPath = "/WEB-INF/files/JAVASCRIPTPROG.txt";
     String absoluteDiskPath = this.getServletContext().getRealPath(relativeWebPath);
     File file = new File(absoluteDiskPath);
     FileInputStream fstream = new FileInputStream(file);
     // Get the object of DataInputStream
     DataInputStream in = new DataInputStream(fstream);
     BufferedReader br = new BufferedReader(new InputStreamReader(in));
     String strLine;
     // Read File Line By Line
     while ((strLine = br.readLine()) != null) {
       // Print the content on the console
       out.println(strLine);
     }
     // Close the input stream
     in.close();
   } catch (Exception e) { // Catch exception if any
     out.println("Error: " + e.getMessage());
   }
   if (session.isNew() || session.getAttribute("session.PanierListe") == null)
     out.println("<a href=\"admin/admin.html\">Caddie (vide)</a></font><br></p>");
   else if (session.getAttribute("session.PanierListe") != null)
     if (((PanierListe) session.getAttribute("session.PanierListe")).getSize() > 0)
       out.println(
           "<a href=\"admin/admin.html\">afficher caddie("
               + ((PanierListe) session.getAttribute("session.PanierListe")).Liste.size()
               + "Representations dans le panier)"
               + "</a></font><br></p>");
   try {
     Utilisateur user = Utilitaires.Identification(this);
     out.println(Utilitaires.AffichageAchat(user));
   } catch (Exception e) {
     out.println(e.getMessage());
   }
   out.println("</BODY>");
   out.close();
 }
예제 #5
0
 private void handleToken(Exception err, HttpMessage response) {
   if (err == null) {
     this.doParseTokenResponse(response);
   } else {
     logger.error(
         new StringWriter().append("handleToken(): ").append(err.getMessage()).toString());
     this.setError(new WString(err.getMessage()));
   }
   WApplication app = WApplication.getInstance();
   if (app.getEnvironment().hasAjax()) {
   } else {
     this.onOAuthDone();
     app.redirect(app.url(this.startInternalPath_));
   }
 }
예제 #6
0
  public String checkValidLogin(String myUserName, String myPW) {

    try {
      Class.forName(javaSQLDriverPath);
      Connection conn =
          (Connection) DriverManager.getConnection(ConnectionPath, ConnectionUser, ConnectionPW);
      Statement st = conn.createStatement();
      String query = "Select * from User";

      ResultSet rs = st.executeQuery(query);
      while (rs.next()) {
        // return rs.getString("Username");
        if (myUserName.equals(rs.getString("Username"))) {
          if (myPW.equals(rs.getString("Password"))) {
            setUserVariables(myUserName);
            return "success";
          } else {
            return "wrongPassword";
          }
        }
      }

      rs.close();
      st.close();
      conn.close();

      return "userNotFound";
    } catch (Exception e) {

      return e.getMessage();
    }
  }
  public void service(HttpServletRequest request, HttpServletResponse response)
      throws IOException, ServletException {

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    try {
      userObj = new User();
      tmsManager = new TMSManager();

      RequestDispatcher rd1 = request.getRequestDispatcher("./header");
      rd1.include(request, response);

      out.println("<html><head><title>UpdateUser</title></head>");
      out.println("<body onload=onSubmit() bgcolor =\"#ffcc00\">");
      out.println("<form  method =\"POST\"  action =\"./updateUser\" ><br><br><br>");
      out.println("<table border = 1 width = \"40%\" align = \"center\" bgcolor = \"#bbccff\">");
      out.println("<caption><b>UpdateUser</b></caption>");
      out.println("<tr><td style = font face: verdana>Enter User ID</td>");
      out.println("<td><input type = \"text\" name = \"user_id\" ></td></tr>");
      out.println(
          "<tr><td colspan = 2 align = \"center\"><input type = \"submit\"  name = \"Submit\" value = \"Submit\">");
      out.println("<input type = \"Reset\"  name = \"Reset\" value = \"Clear\"></td></tr>");
      out.println("</table>");
      out.println("</body></html>");

      // String user_id = request.getParameter("user_id");
      //    userObj = tmsManager.getUser(user_id);
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }

    RequestDispatcher rd2 = request.getRequestDispatcher("./footer");
    rd2.include(request, response);
  }
예제 #8
0
 private void doMailBackup() {
   try {
     rmtApi.createConfigBackupFile(RemoteApi.BackupFileDisposition.Mail);
   } catch (Exception e) {
     errMsg = "Error: " + e.getMessage();
   }
 }
예제 #9
0
  String formatScriptResultHTML(
      String script, Object result, Exception error, StringBuffer scriptOutput) throws IOException {
    SimpleTemplate tmplt;

    if (error != null) {
      tmplt = new SimpleTemplate(getClass().getResource("error.template"));

      String errString;

      if (error instanceof bsh.EvalError) {
        int lineNo = ((EvalError) error).getErrorLineNumber();
        String msg = error.getMessage();
        int contextLines = 4;
        errString = escape(msg);
        if (lineNo > -1) errString += "<hr>" + showScriptContextHTML(script, lineNo, contextLines);
      } else errString = escape(error.toString());

      tmplt.replace("error", errString);
    } else {
      tmplt = new SimpleTemplate(getClass().getResource("result.template"));
      tmplt.replace("value", escape(String.valueOf(result)));
      tmplt.replace("output", escape(scriptOutput.toString()));
    }

    return tmplt.toString();
  }
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   ProfesorRepository profesores = (ProfesorRepository) context.getBean("profesorRepository");
   try {
     String id = request.getParameter("id");
     int idProf = Integer.parseInt(id);
     String cedula = request.getParameter("cedula");
     String nombre = request.getParameter("nombre");
     String titulo = request.getParameter("titulo");
     String area = request.getParameter("area");
     String telefono = request.getParameter("telefono");
     Profesor prof = profesores.findProfesor(idProf);
     try {
       if (cedula != null) prof.setCedula(cedula);
       if (nombre != null) prof.setNombre(nombre);
       if (titulo != null) prof.setTitulo(titulo);
       if (area != null) prof.setArea(area);
       if (telefono != null) prof.setTelefono(telefono);
       profesores.updateProfesor(prof);
     } catch (Exception e) {
     }
     response.sendRedirect("listaProfesores");
   } catch (Exception e) {
     request.setAttribute("mensaje", e.getMessage());
     forward("/paginaError.jsp", request, response);
   }
 }
예제 #11
0
  // getListOfSharesByType -
  private Map<String, String> getListOfSharesByType(
      String type, HttpServletRequest request, HttpServletResponse response) {
    Map<String, String> allShares = new HashMap<String, String>();

    // publishedSources - array of source._ids of published sources
    ArrayList<String> publishedSources = new ArrayList<String>();
    try {
      JSONObject sharesObject = new JSONObject(searchSharesByType(type, request, response));
      JSONObject json_response = sharesObject.getJSONObject("response");

      if (json_response.getString("success").equalsIgnoreCase("true")) {
        if (sharesObject.has("data")) {
          // Iterate over share objects and write to our collection
          JSONArray shares = sharesObject.getJSONArray("data");
          for (int i = 0; i < shares.length(); i++) {
            JSONObject share = shares.getJSONObject(i);
            allShares.put(share.getString("title"), share.getString("_id"));
          }
        }
      }
    } catch (Exception e) {
      System.out.println(e.getMessage());
    }
    return allShares;
  }
예제 #12
0
 public void destroy() {
   super.destroy();
   try {
     link.close();
   } catch (Exception e) {
     System.err.println(e.getMessage());
   }
 }
예제 #13
0
  public static void init() throws ServletException {
    try {
      // récupération de la source de donnée
      Context initCtx = new InitialContext();
      ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/digitlibpool");

    } catch (Exception e) {
      throw new UnavailableException(e.getMessage());
    }
  }
예제 #14
0
 // This happens very early - check it.
 static {
   try {
     log = LogFactory.getLog(Servlet.class);
   } catch (Exception ex) {
     System.err.println("Exception creating the logger");
     System.err.println("Commons logging jar files in WEB-INF/lib/?");
     System.err.println(ex.getMessage());
     // ex.printStackTrace(System.err) ;
   }
 }
예제 #15
0
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    try {
      System.out.println(request.getReader().readLine());
    } catch (Exception e) {
      // e.printStackTrace();
      _log.error(" error " + e.getMessage());
    }
  }
 /*
  * Inicialización del servlet
  */
 public final void init() throws ServletException {
   try {
     // new es.tid.frawa.common.TdiFrawaTraceListener().trace(getClass().getName() + ".init()");
     new es.tid.frawa.common.TdiFrawaTraceListener().trace(getClass().getName() + ".init()");
     frawaInit();
   } catch (Exception e) {
     // new es.tid.frawa.common.TdiFrawaTraceListener().trace(e);
     new es.tid.frawa.common.TdiFrawaTraceListener().trace(e);
     throw new ServletException(getClass().getName() + ".init() " + e.getMessage());
   }
 }
예제 #17
0
  public void destroy() {
    try {
      System.out.println("Stopping Penrose Server...");
      penroseServer.stop();

      System.out.println("Penrose Server stopped.");

    } catch (Exception e) {
      System.out.println("Failed stopping Penrose Server: " + e.getMessage());
    }
  }
 /**
  * Utilizado como controlador de página para la acción de listar medidores.
  *
  * @param request
  * @param response
  * @throws ServletException
  * @throws IOException
  */
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   MedidorModule module = (MedidorModule) context.getBean("medidorModule");
   try {
     List data = module.listado();
     request.setAttribute("medidores", data);
     forward("/listaMedidores.jsp", request, response);
   } catch (Exception e) {
     request.setAttribute("mensaje", e.getMessage());
     forward("/paginaError.jsp", request, response);
   }
 }
예제 #19
0
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   String zip = request.getParameter("zip");
   WeatherService weatherService = new WeatherService();
   PrintWriter out = response.getWriter();
   try {
     out.println(weatherService.retrieveForecast(zip));
   } catch (Exception e) {
     out.println("Error Retrieving Forecast: " + e.getMessage());
   }
   out.flush();
   out.close();
 }
예제 #20
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();
    }
  }
  public int doStartTag() throws JspException {
    try {
      HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
      ModuleContext context = (ModuleContext) request.getSession().getAttribute("context");

      String viewObject = request.getParameter("viewObject");
      viewObject = (viewObject == null || viewObject.equals("")) ? "xava_view" : viewObject;
      View view = (View) context.get(request, viewObject);

      MetaReference metaReference = view.getMetaReference(reference).cloneMetaReference();
      metaReference.setName(reference);
      String prefix = request.getParameter("propertyPrefix");
      prefix = prefix == null ? "" : prefix;
      String application = request.getParameter("application");
      String module = request.getParameter("module");
      String referenceKey = Ids.decorate(application, module, prefix + reference);
      request.setAttribute(referenceKey, metaReference);
      String editorURL =
          "reference.jsp?referenceKey="
              + referenceKey
              + "&onlyEditor=true&frame=false&composite=false&descriptionsList=true";
      String editorPrefix = Module.isPortlet() ? "/WEB-INF/jsp/xava/" : "/xava/";
      try {
        pageContext.include(editorPrefix + editorURL);
      } catch (ServletException ex) {
        Throwable cause = ex.getRootCause() == null ? ex : ex.getRootCause();
        log.error(cause.getMessage(), cause);
        pageContext.include(editorPrefix + "editors/notAvailableEditor.jsp");
      } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        pageContext.include(editorPrefix + "editors/notAvailableEditor.jsp");
      }
    } catch (Exception ex) {
      log.error(ex.getMessage(), ex);
      throw new JspException(XavaResources.getString("descriptionsList_tag_error", reference));
    }
    return SKIP_BODY;
  }
  private void logSample(HttpSample sample, String outputDirectory) {
    try {
      File file = new File(outputDirectory, getPerformanceLogFileName());
      if (!file.exists()) {
        createNewFile(file);
      }

      insertLine(file, sample);

    } catch (Exception e) {
      Log logger = LogFactory.getLog(PerformanceMeasurementFilter.class);
      logger.warn(e.getMessage(), e);
    }
  }
예제 #23
0
  private boolean disableMetadataIndexing(ArchivalUnit au, boolean force) {
    if (metadataMgr == null) {
      errMsg = "Metadata processing is not enabled.";
      return false;
    }

    try {
      metadataMgr.disableAuIndexing(au);
      statusMsg = "Disabled metadata indexing for " + au.getName();
      return true;
    } catch (Exception e) {
      errMsg = "Cannot reindex metadata for " + au.getName() + ": " + e.getMessage();
      return false;
    }
  }
예제 #24
0
파일: AddSong.java 프로젝트: mode14/myfavs
  public void doPost(HttpServletRequest req, HttpServletResponse res)
      throws IOException, ServletException {

    res.setContentType("text/html");
    PrintWriter out = res.getWriter();

    /* Get Session */
    HttpSession s = req.getSession(true);
    /* Make sure user is logged in */
    if (s.getAttribute("login") == null || (String) s.getAttribute("login") != "go") {
      req.getRequestDispatcher("login.jsp").forward(req, res);
    }

    try {
      String dbuser = this.getServletContext().getInitParameter("dbuser");
      String dbpassword = this.getServletContext().getInitParameter("dbpassword");

      Class.forName("com.mysql.jdbc.Driver");
      Connection conn =
          DriverManager.getConnection("jdbc:mysql://localhost/project", dbuser, dbpassword);

      Statement stmt = conn.createStatement();
      stmt.execute(
          "INSERT INTO songs VALUES(null, '"
              + req.getParameter("song_name")
              + "', '"
              + req.getParameter("artist")
              + "', '"
              + req.getParameter("album")
              + "', '"
              + req.getParameter("genre")
              + "', 0)");

      stmt.close();
      conn.close();

      // delete memcache since new song is now added
      MemcachedClient c = new MemcachedClient(new InetSocketAddress("127.0.0.1", 11211));
      c.delete("master");

      req.getRequestDispatcher("add_song_success.jsp").forward(req, res);

    } catch (Exception e) {
      out.println(e.getMessage());
    }
  }
예제 #25
0
  public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);

    try {
      String home = servletConfig.getInitParameter("penrose.home");

      System.out.println("Starting Penrose Server at " + home + "...");
      penroseServer = new PenroseServer(home);
      penroseServer.start();

      System.out.println("Penrose Server started.");

    } catch (Exception e) {
      System.out.println("Failed starting Penrose Server: " + e.getMessage());
      throw new ServletException(e);
    }
  }
예제 #26
0
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   String fn = getServletContext().getRealPath("/WEB-INF/counter.txt");
   String strBefore = "";
   String strAfter = "";
   int counter = 0;
   Integer n = null;
   BufferedReader br = null;
   BufferedWriter bw = null;
   response.setContentType("text/html;charset=UTF-8");
   PrintWriter out = response.getWriter();
   out.println("<html><head><title>Sync Test</title></head><body>");
   out.println("<h2> Block Synchronized</h2>");
   try {
     synchronized (this) {
       // カウンターを読む
       br = new BufferedReader(new FileReader(fn));
       strBefore = br.readLine();
       br.close();
       // カウンターを増やす
       counter = Integer.parseInt(strBefore);
       counter++;
       n = new Integer(counter);
       strAfter = n.toString();
       // カウンターを書き込む
       bw = new BufferedWriter(new FileWriter(fn));
       bw.write(strAfter);
       bw.close();
     }
   } catch (Exception e) {
     out.println("エラー:" + e.getMessage() + "<br><pre>");
     e.printStackTrace(out);
     out.println("</pre>");
   }
   out.println("現在のカウント:" + strBefore + "<p>");
   out.println("更新後のカウント:" + strAfter + "<p>");
   ServletContext context = getServletContext();
   String s = (String) context.getAttribute("lastsvl");
   out.println("<p>lastsvl: " + s);
   context.setAttribute("lastsvl", "SynchronizedTest");
   out.println("</body></html>");
   out.close();
 }
예제 #27
0
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   ProfesorRepository profesores = (ProfesorRepository) context.getBean("profesorRepository");
   try {
     Collection lista = profesores.findAllProfesor();
     List data = new ArrayList();
     Iterator itr = lista.iterator();
     while (itr.hasNext()) {
       Profesor prof = (Profesor) itr.next();
       ProfesorDTO dto = ProfesorAssembler.Create(prof);
       data.add(dto);
     }
     request.setAttribute("profesores", data);
     forward("/listaProfesores.jsp", request, response);
   } catch (Exception e) {
     request.setAttribute("mensaje", e.getMessage());
     forward("/paginaError.jsp", request, response);
   }
 }
예제 #28
0
 public void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   GrupoRepository grupos = (GrupoRepository) context.getBean("grupoRepository");
   try {
     Collection lista = grupos.findAllGrupo();
     List data = new ArrayList();
     Iterator itr = lista.iterator();
     while (itr.hasNext()) {
       Grupo grupo = (Grupo) itr.next();
       GrupoDTO dto = GrupoAssembler.CreateDTO(grupo);
       data.add(dto);
     }
     request.setAttribute("grupos", data);
     forward("/listaGrupos.jsp", request, response);
   } catch (Exception e) {
     request.setAttribute("mensaje", e.getMessage());
     forward("/paginaError.jsp", request, response);
   }
 }
예제 #29
0
 /** checks database for this user */
 private boolean realAuthentication(HttpServletRequest request, ConnectionPool conPool)
     throws SQLException {
   // user authentication is required!
   User user = (User) request.getSession().getAttribute(StringInterface.USERATTR);
   if (user == null) {
     return false;
   }
   Connection con = conPool.getConnection();
   boolean authenticated = false;
   try {
     authenticated = userUtils.confirmUserWithEncrypted(user.getID(), user.getEncrypted(), con);
   } catch (Exception e) {
     throw new SQLException(e.getMessage());
   } finally {
     conPool.free(con);
     con = null;
   }
   return authenticated;
 } // end realAuthentication
예제 #30
0
 // getListOfAllCommunities
 private Map<String, String> getListOfAllNonPersonalCommunities(
     HttpServletRequest request, HttpServletResponse response) {
   Map<String, String> allCommunities = new HashMap<String, String>();
   try {
     JSONObject communitiesObj = new JSONObject(getAllCommunities(request, response));
     if (communitiesObj.has("data")) {
       JSONArray communities = communitiesObj.getJSONArray("data");
       for (int i = 0; i < communities.length(); i++) {
         JSONObject community = communities.getJSONObject(i);
         if (community.getString("isPersonalCommunity").equalsIgnoreCase("false")
             && community.has("name")) {
           allCommunities.put(community.getString("name"), community.getString("_id"));
         }
       }
     }
   } catch (Exception e) {
     System.out.println(e.getMessage());
   }
   return allCommunities;
 }