
1. Template
1) WebContent - view - template - sidebar.jsp 수정
22 | < p >< a href = "${pageContext.request.contextPath}/DispatcherServlet?command=updatePage" >회원수정</ a ></ p > |
2. View
1) WebContent - view - member - update.jsp 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> < div class = "card" > < form action = "DispatcherServlet" method = "post" > < input type = "hidden" name = "command" value = "update" > < table > < tr > < td >아이디</ td > < td >< input type = "text" name = "clientId" value = "${clientDTOinfo.clientId}" readonly></ td > </ tr > < tr > < td >비밀번호</ td > < td >< input type = "password" name = "clientPassword" ></ td > </ tr > < tr > < td >이름</ td > < td >< input type = "text" name = "clientName" value = "${clientDTOinfo.clientName}" ></ td > </ tr > < tr > < td >이메일</ td > < td >< input type = "text" name = "clientEmail" value = "${clientDTOinfo.clientEmail}" ></ td > </ tr > < tr > < td >전화번호</ td > < td >< input type = "text" name = "clientPhone" value = "${clientDTOinfo.clientPhone}" ></ td > </ tr > < tr > < td >주소</ td > < td >< input type = "text" name = "clientAddress" value = "${clientDTOinfo.clientAddress}" ></ td > </ tr > < tr rowspan = "2" > < td >< input type = "submit" value = "수정" /></ td > </ tr > </ table > </ form > </ div > |
2) WebContent - view - member - update_result.jsp 추가
1 2 3 4 5 6 7 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> < script > alert("수정이 완료되었습니다."); </ script > |
3. Model
1) src - model.ClientDAO.java에 getClientInfo 메소드 추가(회원 수정페이지에 정보 띄우기 위해)
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | //3. 아이디로 회원정보 찾기(패스워드 제외) public ClientDTO getClientInfo(String clientId) throws SQLException { Connection con = null ; PreparedStatement pstmt = null ; ResultSet rs= null ; ClientDTO resultDTO= null ; try { con = getConnection(); String sql= "select * from client where clientId=?" ; pstmt = con.prepareStatement(sql); pstmt.setString( 1 , clientId); rs=pstmt.executeQuery(); if (rs.next()) resultDTO = new ClientDTO(rs.getString( 1 ), null , rs.getString( 3 ), rs.getString( 4 ), rs.getString( 5 ), rs.getString( 6 )); } catch (SQLException e) { e.printStackTrace(); } finally { closeAll(rs,pstmt, con); } return resultDTO; } |
2) src - test.TestGetClientInfo.java 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | package test; import java.sql.SQLException; import model.ClientDAO; import model.ClientDTO; public class TestGetClientInfo { public static void main(String[] args) { String clientId= "xiumin" ; try { ClientDTO clientDTOinfo=ClientDAO.getInstance().getClientInfo(clientId); System.out.println(clientDTOinfo); } catch (SQLException e) { e.printStackTrace(); } } } |
3) src - model.ClientDAO.java에 updateMemberInfo 메소드 추가
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | public void updateMemberInfo(ClientDTO clientDTO) throws SQLException { Connection con = null ; PreparedStatement pstmt = null ; try { con = getConnection(); String sql = "update client set clientPassword=?, clientName=?, clientEmail=?,clientPhone=?,clientAddress=? where clientId=?" ; pstmt = con.prepareStatement(sql); pstmt.setString( 1 , clientDTO.getClientPassword()); pstmt.setString( 2 , clientDTO.getClientName()); pstmt.setString( 3 , clientDTO.getClientEmail()); pstmt.setString( 4 , clientDTO.getClientPhone()); pstmt.setString( 5 , clientDTO.getClientAddress()); pstmt.setString( 6 , clientDTO.getClientId()); pstmt.execute(); } catch (SQLException e) { e.printStackTrace(); } finally { closeAll(pstmt, con); } } |
4) src - test.TestUpdateMemberInfo.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | package test; import java.sql.SQLException; import model.ClientDAO; import model.ClientDTO; public class TestUpdateMemberInfo { public static void main(String[] args) { try { ClientDTO oldInfo=ClientDAO.getInstance().getClientInfo( "suman" ); System.out.println( "예전정보 : " +oldInfo); ClientDTO newInfo= new ClientDTO( "suman" , "sm1234" , "이수만" , "smNo1@smtown.com" , "010-0000-0000" , "SM공화국" ); System.out.println( "변경정보 : " +newInfo); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } |
4. Controller
1) src - controller.HandlerMapping.java 에 updatePage,update 추가
23 24 25 26 | else if (command.equals( "updatePage" )) // 회원수정 페이지 이동 c= new UpdatePageController(); else if (command.equals( "update" )) //회원수정 처리 c= new UpdateController(); |
2) src - controller.UpdatePageController.java 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import model.ClientDAO; import model.ClientDTO; public class UpdatePageController implements Controller { @Override public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession( false ); ClientDTO clientDTO=(ClientDTO) session.getAttribute( "clientDTO" ); if (session== null ||session.getAttribute( "clientDTO" )== null ){ return "redirect:index.jsp" ; } ClientDTO clientDTOinfo=ClientDAO.getInstance().getClientInfo(clientDTO.getClientId()); request.setAttribute( "clientDTOinfo" , clientDTOinfo); request.setAttribute( "url" , "/view/member/update.jsp" ); return "/view/template/home.jsp" ; } } |
3) src - controller.update.java 추가
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | package controller; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import model.ClientDAO; import model.ClientDTO; public class UpdateController implements Controller { @Override public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession( false ); if (session== null ||session.getAttribute( "clientDTO" )== null ){ return "redirect:index.jsp" ; } String clientId=request.getParameter( "clientId" ); String clientPassword=request.getParameter( "clientPassword" ); String clientName=request.getParameter( "clientName" ); String clientEmail=request.getParameter( "clientEmail" ); String clientPhone=request.getParameter( "clientPhone" ); String clientAddress=request.getParameter( "clientAddress" ); ClientDTO dto = new ClientDTO(clientId, clientPassword, clientName, clientEmail, clientPhone, clientAddress); ClientDAO.getInstance().updateMemberInfo(dto); return "redirect:view/member/update_result.jsp" ; } } |
'1.JAVA Web Programming > [4주차] 게시판 만들기' 카테고리의 다른 글
게시판 - webstudy-board - 게시판 글목록 (0) | 2019.08.11 |
---|---|
게시판 - webstudy-board - 회원탈퇴 (0) | 2019.08.11 |
게시판 - webstudy-board - 로그인/로그아웃 (0) | 2019.08.11 |
게시판 - webstudy-board - 회원가입 (0) | 2019.08.11 |
게시판 - webstudy-board - Index 페이지 (0) | 2019.08.11 |