/**
   * 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, ParseException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    // String dateString = request.getParameter("tanggalawal");
    // String tanggalString = request.getParameter("tanggalkhir");
    // SimpleDateFormat dateFormat = new SimpleDateFormat("dd/mm/yyyy");
    // Date awal = dateFormat.parse(dateString);
    // Date akhir = dateFormat.parse(tanggalString);
    String sem = request.getParameter("namasemester");
    String tahun = request.getParameter("tahunajaran");
    DaftarSemester daftar = new DaftarSemester();
    Semester semester = new Semester();

    if (sem.isEmpty() || tahun.isEmpty()) {
      request.setAttribute("Peringatan", "Semua kolom harus di isi!");
      RequestDispatcher rdp = request.getRequestDispatcher("pages/tambahsemester.jsp");
      rdp.forward(request, response);

    } else if (daftar.check(sem, tahun) == true) {
      request.setAttribute("Peringatan", "Nama Semester sudah digunakan");
      RequestDispatcher rdp = request.getRequestDispatcher("pages/tambahsemester.jsp");
      rdp.forward(request, response);

    } else {

      semester.setNamasemester(sem);
      semester.setTahunajaran(tahun);
      // semester.setTanggalawal(awal);
      // semester.setTanggalakhir(akhir);

      daftar.addSemester(semester);
      RequestDispatcher rdp = request.getRequestDispatcher("pages/tambahsemester.jsp");
      rdp.forward(request, response);
    }

    try {

    } finally {
      out.close();
    }
  }
Exemple #2
0
  /**
   * 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 {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

    Long id = Long.parseLong(request.getParameter("id"));

    DaftarSiswa siswax = new DaftarSiswa();
    Siswa siswa = siswax.findSiswa(id);

    DaftarKelas daftarkelas = new DaftarKelas();
    List<Kelas> kelas = daftarkelas.getKelasx();
    request.setAttribute("listkelas", kelas);

    DaftarSemester daftarsemester = new DaftarSemester();
    List<Semester> semester = daftarsemester.getSemester();
    request.setAttribute("listsemester", semester);

    HttpSession sessionedit = request.getSession();
    sessionedit.setAttribute("siswa", siswa);
    request.setAttribute("siswa", siswa);

    try {
      RequestDispatcher rdp = request.getRequestDispatcher("pages/UbahSiswa.jsp");
      rdp.forward(request, response);
      /* TODO output your page here
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Servlet ProsesUbahSiswa</title>");
      out.println("</head>");
      out.println("<body>");
      out.println("<h1>Servlet ProsesUbahSiswa at " + request.getContextPath () + "</h1>");
      out.println("</body>");
      out.println("</html>");
       */
    } finally {
      out.close();
    }
  }