package web.UserRelated;

import pojo.User;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/main/update_user_Info")
public class update_user_Info extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("Utf-8");
        User user=(User)request.getSession().getAttribute("user");
        user.setAddress(request.getParameter("address"));
        user.setGender(request.getParameter("gender"));
        user.setName(request.getParameter("name"));
        System.out.println(request.getParameter("phone"));
        user.setTelephone(request.getParameter("phone"));
        UserService service=new UserService();
        System.out.println(user.getTelephone());
        try {
            service.updateUser(user);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        request.getSession().setAttribute("user",user);
        request.getRequestDispatcher("/main/user/user-Info.jsp").forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }
}


