Advertisement
Guest User

editprofileservlet

a guest
May 30th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.13 KB | None | 0 0
  1. package Servlets;
  2.  
  3. /*
  4.  * To change this license header, choose License Headers in Project Properties.
  5.  * To change this template file, choose Tools | Templates
  6.  * and open the template in the editor.
  7.  */
  8.  
  9. import Services.editProfileService;
  10. import Services.userInfo;
  11. import java.io.IOException;
  12. import java.io.PrintWriter;
  13. import java.util.logging.Level;
  14. import java.util.logging.Logger;
  15. import javax.servlet.ServletException;
  16. import javax.servlet.annotation.WebServlet;
  17. import javax.servlet.http.HttpServlet;
  18. import javax.servlet.http.HttpServletRequest;
  19. import javax.servlet.http.HttpServletResponse;
  20.  
  21. /**
  22.  *
  23.  * @author ab1d_rahman
  24.  */
  25. @WebServlet(urlPatterns = {"/editProfileServlet"})
  26. public class editProfileServlet extends HttpServlet {
  27.  
  28.     /**
  29.      * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
  30.      * methods.
  31.      *
  32.      * @param request servlet request
  33.      * @param response servlet response
  34.      * @throws ServletException if a servlet-specific error occurs
  35.      * @throws IOException if an I/O error occurs
  36.      */
  37.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  38.             throws ServletException, IOException {
  39.         response.setContentType("text/html;charset=UTF-8");
  40.         PrintWriter out = response.getWriter();
  41.         try {
  42.             /* TODO output your page here. You may use following sample code. */
  43.             out.println("<!DOCTYPE html>");
  44.             out.println("<html>");
  45.             out.println("<head>");
  46.             out.println("<title>Servlet editProfileServlet</title>");            
  47.             out.println("</head>");
  48.             out.println("<body>");
  49.             out.println("<h1>Servlet editProfileServlet at " + request.getContextPath() + "</h1>");
  50.             out.println("</body>");
  51.             out.println("</html>");
  52.         } finally {
  53.             out.close();
  54.         }
  55.     }
  56.  
  57.     // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
  58.     /**
  59.      * Handles the HTTP <code>GET</code> method.
  60.      *
  61.      * @param request servlet request
  62.      * @param response servlet response
  63.      * @throws ServletException if a servlet-specific error occurs
  64.      * @throws IOException if an I/O error occurs
  65.      */
  66.     @Override
  67.     protected void doGet(HttpServletRequest request, HttpServletResponse response)
  68.             throws ServletException, IOException {
  69.         processRequest(request, response);
  70.     }
  71.  
  72.     /**
  73.      * Handles the HTTP <code>POST</code> method.
  74.      *
  75.      * @param request servlet request
  76.      * @param response servlet response
  77.      * @throws ServletException if a servlet-specific error occurs
  78.      * @throws IOException if an I/O error occurs
  79.      */
  80.     @Override
  81.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  82.             throws ServletException, IOException {
  83.        
  84.         String password, firstName, lastName, phoneNo;
  85.         password = request.getParameter("password");
  86.         firstName = request.getParameter("firstName");
  87.         lastName = request.getParameter("lastName");
  88.         phoneNo = request.getParameter("phoneNo");
  89.        
  90.         if(password == "" && firstName == "" && lastName == "" && phoneNo == "") response.sendRedirect("editProfile.jsp");
  91.         else{
  92.         userInfo uI = new userInfo(null, password, firstName, lastName, phoneNo);
  93.        
  94.         editProfileService EditProfileService;
  95.         EditProfileService = new editProfileService();
  96.        
  97.         try {
  98.             if(EditProfileService.editProfile(uI, request.getSession())){
  99.                 response.sendRedirect("editProfileSuccessful.jsp");
  100.             }
  101.         } catch (ClassNotFoundException ex) {
  102.             Logger.getLogger(editProfileServlet.class.getName()).log(Level.SEVERE, null, ex);
  103.         }
  104.         }
  105.     }
  106.  
  107.     /**
  108.      * Returns a short description of the servlet.
  109.      *
  110.      * @return a String containing servlet description
  111.      */
  112.     @Override
  113.     public String getServletInfo() {
  114.         return "Short description";
  115.     }// </editor-fold>
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement