controller/member/MemberModify.java
페이지 정보
본문
package controller.member;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
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 javax.servlet.http.HttpSession;
import dao.MemberDAO;
import model.Member;
@WebServlet("/member/modify")
public class MemberModify extends HttpServlet {
private static final long serialVersionUID = 1L;
public MemberModify() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
String session_id = (String)session.getAttribute("id");
if(session_id == null) { //로그인 처리 안 했을 경우 경고
response.setContentType("text/html; charset=utf-8");
PrintWriter out = response.getWriter();
out.print("<script>");
out.print("alert('잘못된 경로입니다.');");
out.print("location.href='/'");
out.print("</script>");
out.close();
}else {
MemberDAO dao = new MemberDAO();
Member m = dao.oneMember(session_id);
request.setAttribute("modify", m); //객체 modify를 modify.jsp로 forward() 시킨다.
RequestDispatcher dis = request.getRequestDispatcher("modify.jsp");
dis.forward(request, response);
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
Member m = new Member();
// <form>넘어온 변수들을 객체에 담는다.
m.setId(request.getParameter("mb_id"));
m.setPass(request.getParameter("mb_pass"));
m.setName(request.getParameter("mb_name"));
m.setAge(Integer.parseInt(request.getParameter("mb_age")));
m.setGender(request.getParameter("mb_gender"));
m.setEmail(request.getParameter("mb_email"));
m.setMemo(request.getParameter("mb_memo"));
MemberDAO dao = new MemberDAO();
dao.updateMember(m);
response.sendRedirect("modify"); //수정(doGet) 서블릿 이동
}
}
- 이전글controller/member/MemberJoin.java 23.03.17
- 다음글dao/MemberDAO.java 23.03.17
댓글목록
등록된 댓글이 없습니다.