diff --git a/IF3110-02-Simple-Blog-Java/build.xml b/IF3110-02-Simple-Blog-Java/build.xml
new file mode 100644
index 00000000..ec29b4ea
--- /dev/null
+++ b/IF3110-02-Simple-Blog-Java/build.xml
@@ -0,0 +1,71 @@
+
+
+
+
+
+
+
+
+
+
<%= post.getKonten() %>
+ +GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ String id = request.getParameter("id");
+
+ if (request.getSession().getAttribute("currentUser") == null) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ Post editedPost = PostDAO.getPost(Integer.valueOf(id));
+ if (editedPost != null) {
+ request.getSession().setAttribute("editedImagePost", editedPost);
+ response.sendRedirect("AddImagePost.jsp");
+ } else {
+ response.sendRedirect("PublishedPosts");
+ }
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ String appPath = request.getServletContext().getRealPath("");
+ System.out.println("APPPATH = " + appPath);
+ String savePath = appPath + File.separator + SAVE_DIR;
+ System.out.println("SAVEPATH = " + savePath);
+
+ // creates the save directory if it does not exists
+ File fileSaveDir = new File(savePath);
+ if (!fileSaveDir.exists()) {
+ fileSaveDir.mkdir();
+ }
+ Part part = request.getPart("file");
+ System.out.println(part.getName());
+ System.out.println(part.getSize());
+ System.out.println(part.getSubmittedFileName());
+ String fileName = extractFileName(part);
+ System.out.println("WRITEPATH = " + savePath + File.separator + fileName);
+ System.out.println(fileName);
+ part.write(fileName);
+
+ if (PostDAO.addImage(fileName, Integer.valueOf(request.getParameter("id")))) {
+ request.getSession().setAttribute("ImagePostStatus", "Gambar post berhasil disimpan");
+ response.sendRedirect("ImagePostStatus.jsp");
+ } else {
+ request.getSession().setAttribute("ImagePostStatus", "Gambar post tidak berhasil disimpan");
+ response.sendRedirect("ImagePostStatus.jsp");
+ }
+
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ if (request.getSession().getAttribute("currentUser") == null ||
+ ((User)request.getSession().getAttribute("currentUser")).getRole().equals("Editor")) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ response.sendRedirect("AddNewPost.jsp");
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ try {
+ System.out.println("TANGGAL PARAMETER => " + request.getParameter("tanggal"));
+ Post post = new Post();
+ post.setJudul(request.getParameter("judul"));
+ post.setTanggal(new SimpleDateFormat("MM/dd/yyyy").parse(request.getParameter("tanggal")));
+ post.setKonten(request.getParameter("konten"));
+ post.setStatus("Unpublished");
+
+ if (!PostDAO.add(post)) {
+ request.getSession().setAttribute("AddNewPostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" gagal disimpan");
+ } else {
+ request.getSession().setAttribute("AddNewPostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" berhasil disimpan");
+ }
+ response.sendRedirect("AddNewPostStatus.jsp");
+ processRequest(request, response);
+ } catch (ParseException ex) {
+ Logger.getLogger(AddNewPostServlet.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ String id = request.getParameter("id");
+
+ if (request.getSession().getAttribute("currentUser") == null) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ if (!PostDAO.delete(Integer.valueOf(id))) {
+ request.getSession().setAttribute("DeletePostStatus", "Post (id = " + id + ") tidak berhasil dihapus");
+ response.sendRedirect("DeletePostStatus.jsp");
+ } else {
+ request.getSession().setAttribute("DeletePostStatus", "Post (id = " + id + ") berhasil dihapus");
+ response.sendRedirect("DeletePostStatus.jsp");
+ }
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ String email = URLDecoder.decode(request.getParameter("email"), "UTF-8");
+
+ if (request.getSession().getAttribute("currentUser") == null ||
+ !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin") ||
+ email.equals("") || email == null) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ if (!UserDAO.delete(email)) {
+ request.getSession().setAttribute("deleteUser", "User dengan email " + email + " tidak ditemukan");
+ response.sendRedirect("DeletionStatus.jsp");
+ } else {
+ request.getSession().setAttribute("deleteUser", "User dengan email " + email + " berhasil dihapus");
+ response.sendRedirect("DeletionStatus.jsp");
+ }
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ }
+ }
+
+ // GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ ArrayList"+isiKomentar+"
POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ try {
+ HttpSession session = null;
+ String sessionCookie = CookieManager.getCookieValue(request, "JSESSIONID");
+ String persistentCookie = CookieManager.getCookieValue(request, "wbdahey");
+
+ if (sessionCookie != null) {
+ if (persistentCookie == null) {
+ CookieManager.addCookie(response, "wbdahey", sessionCookie, 3600*24*365*1000);
+ }
+ }
+
+ if (persistentCookie != null) {
+ HashMapPOST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ try {
+ User user = new User();
+ user.setEmail(URLDecoder.decode(request.getParameter("email"), "UTF-8"));
+ user.setPassword(request.getParameter("password"));
+
+ user = UserDAO.login(user);
+
+ if (user.getValid()) {
+ Cookie wbdCookie = new Cookie("wbdahey", user.getEmail());
+ wbdCookie.setMaxAge(3600*24*365*1000);
+ response.addCookie(wbdCookie);
+
+ request.getSession().setAttribute("currentUser", user);
+// this.getServletConfig().getServletContext().setAttribute("currentUser", user);
+
+ response.sendRedirect("PublishedPosts");
+ } else if (!user.getValid()) {
+ request.getSession().setAttribute("forbidden", "Username/Password tidak valid");
+ response.setStatus(response.SC_MOVED_TEMPORARILY);
+ response.sendRedirect("Uuuppssss.jsp");
+ }
+ processRequest(request, response);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ CookieManager.removeCookie(response, "JSESSIONID");
+ CookieManager.removeCookie(response, "wbdahey");
+
+ request.getSession().setAttribute("currentUser", null);
+
+ response.sendRedirect("PublishedPosts");
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ String id = request.getParameter("id");
+
+ if (request.getSession().getAttribute("currentUser") == null ||
+ ((User)request.getSession().getAttribute("currentUser")).getRole().equals("Owner")) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ if (!PostDAO.publish(Integer.valueOf(id))) {
+ request.getSession().setAttribute("PublishPostStatus", "Post (id = " + id + ") tidak berhasil di-publish");
+ response.sendRedirect("PublishPostStatus.jsp");
+ } else {
+ request.getSession().setAttribute("PublishPostStatus", "Post (id = " + id + ") berhasil di-publish");
+ response.sendRedirect("PublishPostStatus.jsp");
+ }
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ ArrayListPOST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ if (request.getSession().getAttribute("currentUser") == null ||
+ !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ response.sendRedirect("Register.jsp");
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ User user = new User();
+ user.setEmail(request.getParameter("email"));
+ user.setPassword(request.getParameter("password"));
+ user.setName(request.getParameter("name"));
+ user.setRole(request.getParameter("role"));
+
+ if (UserDAO.register(user)) {
+ request.getSession().setAttribute("registerUser", "User dengan email " + request.getParameter("email") + " berhasil ditambahkan");
+ response.sendRedirect("RegistrationStatus.jsp");
+ } else {
+ request.getSession().setAttribute("registerUser", "Email " + request.getParameter("email") + " telah digunakan");
+ response.sendRedirect("RegistrationStatus.jsp");
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ String id = request.getParameter("id");
+
+ if (request.getSession().getAttribute("currentUser") == null) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ if (PostDAO.removeImage(Integer.valueOf(id))) {
+ request.getSession().setAttribute("ImagePostStatus", "Gambar post berhasil dihapus");
+ response.sendRedirect("ImagePostStatus.jsp");
+ } else {
+ request.getSession().setAttribute("ImagePostStatus", "Gambar post tidak berhasil dihapus");
+ response.sendRedirect("ImagePostStatus.jsp");
+ }
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+// out.println("");
+// out.println("");
+// out.println("");
+// out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ Comment comment = new Comment();
+ comment.setEmail(request.getParameter("email"));
+ comment.setName(request.getParameter("nama"));
+ comment.setTanggal(new Date());
+ comment.setKomentar(request.getParameter("komentar"));
+ comment.setId(Integer.valueOf(request.getParameter("idpost")));
+ System.out.println(CommentDAO.save(comment));
+// if (!CommentDAO.save(comment)) {
+// request.getSession().setAttribute("AddNewPostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" gagal disimpan");
+// } else {
+// request.getSession().setAttribute("AddNewPostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" berhasil disimpan");
+// }
+// response.sendRedirect("AddNewPostStatus.jsp");
+// processRequest(request, response);
+ ArrayList"+isiKomentar+"
GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ if (request.getSession().getAttribute("currentUser") == null ||
+ !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+
+ ArrayListPOST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ if (request.getSession().getAttribute("currentUser") == null ||
+ !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+
+ String id = request.getParameter("id");
+
+ if (request.getSession().getAttribute("currentUser") == null) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ if (!PostDAO.softDelete(Integer.valueOf(id))) {
+ request.getSession().setAttribute("DeletePostStatus", "Post (id = " + id + ") tidak berhasil dihapus");
+ response.sendRedirect("DeletePostStatus.jsp");
+ } else {
+ request.getSession().setAttribute("DeletePostStatus", "Post (id = " + id + ") berhasil dihapus");
+ response.sendRedirect("DeletePostStatus.jsp");
+ }
+ }
+ }
+ processRequest(request, response);
+
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ String id = request.getParameter("id");
+
+ if (request.getSession().getAttribute("currentUser") == null ||
+ !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ if (!PostDAO.unDelete(Integer.valueOf(id))) {
+ request.getSession().setAttribute("UndeletePostStatus", "Post (id = " + id + ") tidak berhasil di-undelete");
+ response.sendRedirect("UndeletePostStatus.jsp");
+ } else {
+ request.getSession().setAttribute("UndeletePostStatus", "Post (id = " + id + ") berhasil di-undelete");
+ response.sendRedirect("UndeletePostStatus.jsp");
+ }
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ if (request.getSession().getAttribute("currentUser") == null ||
+ ((User)request.getSession().getAttribute("currentUser")).getPassword().equals("Owner")) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ ArrayListPOST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ String id = request.getParameter("id");
+
+ if (request.getSession().getAttribute("currentUser") == null) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ Post editedPost = PostDAO.getPost(Integer.valueOf(id));
+ if (editedPost != null) {
+ request.getSession().setAttribute("editedPost", editedPost);
+ response.sendRedirect("EditPost.jsp");
+ } else {
+ response.sendRedirect("PublishedPosts");
+ }
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ try {
+ Post post = new Post();
+ post.setId(Integer.valueOf(request.getParameter("id")));
+ post.setJudul(request.getParameter("judul"));
+ post.setTanggal(new SimpleDateFormat("MM/dd/yyyy").parse(request.getParameter("tanggal")));
+ post.setKonten(request.getParameter("konten"));
+ post.setStatus(request.getParameter("status"));
+
+ if (!PostDAO.update(post)) {
+ request.getSession().setAttribute("UpdatePostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" gagal di-update");
+ } else {
+ request.getSession().setAttribute("UpdatePostStatus", "Post dengan judul \"" + request.getParameter("judul") + "\" berhasil di-update");
+ }
+ response.sendRedirect("UpdatePostStatus.jsp");
+ processRequest(request, response);
+ } catch (ParseException ex) {
+ Logger.getLogger(AddNewPostServlet.class.getName()).log(Level.SEVERE, null, ex);
+ }
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ String email = URLDecoder.decode(request.getParameter("email"), "UTF-8");
+
+ if (request.getSession().getAttribute("currentUser") == null ||
+ !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin") ||
+ email.equals("") || email == null) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ User editedUser = UserDAO.getUser(email);
+ if (editedUser != null) {
+ request.getSession().setAttribute("editedUser", editedUser);
+ response.sendRedirect("EditUser.jsp");
+ } else {
+ response.sendRedirect("PublishedPosts");
+ }
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ User user = new User();
+ user.setId(Integer.parseInt(request.getParameter("id")));
+ user.setEmail(request.getParameter("email"));
+ user.setPassword(request.getParameter("password"));
+ user.setName(request.getParameter("name"));
+ user.setRole(request.getParameter("role"));
+
+ if (UserDAO.update(user)) {
+ request.getSession().setAttribute("updateUser", "User (id = " + request.getParameter("id") + ") berhasil di-update");
+ response.sendRedirect("UpdateUserStatus.jsp");
+ } else {
+ request.getSession().setAttribute("updateUser", "User (id = " + request.getParameter("id") + ") tidak berhasil di-update");
+ response.sendRedirect("UpdateUserStatus.jsp");
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ if (request.getSession().getAttribute("currentUser") == null ||
+ !((User)request.getSession().getAttribute("currentUser")).getRole().equals("Admin")) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ ArrayListPOST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ processRequest(request, response);
+
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// GET
and POST
+ * 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");
+ try (PrintWriter out = response.getWriter()) {
+ /* TODO output your page here. You may use following sample code. */
+ out.println("");
+ out.println("");
+ out.println("");
+ out.println("GET
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doGet(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+
+ String id = request.getParameter("id");
+
+ if (id == null || id.equals("")) {
+ response.sendRedirect("PublishedPosts");
+ } else {
+ Post post = PostDAO.getPost(Integer.valueOf(id));
+ if (post != null) {
+ request.getSession().setAttribute("post", post);
+ response.sendRedirect("ViewPost.jsp");
+ } else {
+ response.sendRedirect("PublishedPosts");
+ }
+ }
+ processRequest(request, response);
+ }
+
+ /**
+ * Handles the HTTP POST
method.
+ *
+ * @param request servlet request
+ * @param response servlet response
+ * @throws ServletException if a servlet-specific error occurs
+ * @throws IOException if an I/O error occurs
+ */
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response)
+ throws ServletException, IOException {
+ processRequest(request, response);
+ }
+
+ /**
+ * Returns a short description of the servlet.
+ *
+ * @return a String containing servlet description
+ */
+ @Override
+ public String getServletInfo() {
+ return "Short description";
+ }// <%= post.getKonten() %>
+ +