src/java/Controllers/SettingsController.java
/**
     * Handles the HTTP <code>POST</code> 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
     */
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
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
    {
        HttpSession session = request.getSession(false);
        User user = new User();
        UserDAO userDAO = new UserDAO();
        if(session.getAttribute("user_id") != null)
        {
            int userid = (Integer) session.getAttribute("user_id");
            user = userDAO.get(userid);
            request.setAttribute("user", user);
        }
        else
        {
            RequestDispatcher rd = request.getRequestDispatcher("views/404.jsp");
            rd.forward(request, response);
        }
        if(session.getAttribute("user_id") != null)
        {
            String firstName = request.getParameter("first_name");
            String lastName = request.getParameter("last_name");
            String email = request.getParameter("email");
            String phoneNumber = request.getParameter("phone_number");
            String password1 = request.getParameter("password1");
            String password2 = request.getParameter("password2");
            if(firstName.length() == 0 || 
               lastName.length() == 0 || 
               email.length() == 0 || 
               phoneNumber.length() == 0 || 
               password1.length() == 0)
            {
                request.setAttribute("message", "Please enter all required data!");
                RequestDispatcher rd = request.getRequestDispatcher("views/settings.jsp");  
                rd.forward(request, response);
                return;
            }
            if(password1.equals(password2))
            {
                password1 = MD5.getMd5(password1);
                int userid = (Integer) session.getAttribute("user_id");
                user.setId(userid);
                user.setFirstName(firstName);
                user.setLastName(lastName);
                user.setEmail(email);
                user.setPhoneNumber(phoneNumber);
                user.setPassword(password1);
                int flag = userDAO.updateUser(user);
                if(flag != 0)
                {
                    request.setAttribute("message", "Done!");
                    RequestDispatcher rd = request.getRequestDispatcher("views/settings.jsp");  
                    rd.forward(request, response);
                    return;
                }
            }
            else
            {
                request.setAttribute("message", "Error!");
                RequestDispatcher rd = request.getRequestDispatcher("views/settings.jsp");  
                rd.forward(request, response);
                return;
            }
        }
    }
@ Override protected void doPost ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { HttpSession session = request . getSession ( false ) ; User user = new User ( ) ; UserDAO userDAO = new UserDAO ( ) ; if ( session . getAttribute ( "user_id" ) != null ) { int userid = ( Integer ) session . getAttribute ( "user_id" ) ; user = userDAO . get ( userid ) ; request . setAttribute ( "user" , user ) ; } else { RequestDispatcher rd = request . getRequestDispatcher ( "views/404.jsp" ) ; rd . forward ( request , response ) ; } if ( session . getAttribute ( "user_id" ) != null ) { String firstName = request . getParameter ( "first_name" ) ; String lastName = request . getParameter ( "last_name" ) ; String email = request . getParameter ( "email" ) ; String phoneNumber = request . getParameter ( "phone_number" ) ; String password1 = request . getParameter ( "password1" ) ; String password2 = request . getParameter ( "password2" ) ; if ( firstName . length ( ) == 0 || lastName . length ( ) == 0 || email . length ( ) == 0 || phoneNumber . length ( ) == 0 || password1 . length ( ) == 0 ) { request . setAttribute ( "message" , "Please enter all required data!" ) ; RequestDispatcher rd = request . getRequestDispatcher ( "views/settings.jsp" ) ; rd . forward ( request , response ) ; return ; } if ( password1 . equals ( password2 ) ) { password1 = MD5 . getMd5 ( password1 ) ; int userid = ( Integer ) session . getAttribute ( "user_id" ) ; user . setId ( userid ) ; user . setFirstName ( firstName ) ; user . setLastName ( lastName ) ; user . setEmail ( email ) ; user . setPhoneNumber ( phoneNumber ) ; user . setPassword ( password1 ) ; int flag = userDAO . updateUser ( user ) ; if ( flag != 0 ) { request . setAttribute ( "message" , "Done!" ) ; RequestDispatcher rd = request . getRequestDispatcher ( "views/settings.jsp" ) ; rd . forward ( request , response ) ; return ; } } else { request . setAttribute ( "message" , "Error!" ) ; RequestDispatcher rd = request . getRequestDispatcher ( "views/settings.jsp" ) ; rd . forward ( request , response ) ; return ; } } }
Handles the HTTP <code>POST</code> method.
Handles the HTTP <code > POST< / code > method .