개발자로가는길
분류 전체보기
(36)
1.JAVA Web Programming
(34)
[0주차]코딩준비
(4)
[1주차] Servlet-Basic
(4)
[2주차]DB,Model1,Model2
(3)
[3주차]JSP+model2
(7)
[4주차] 게시판 만들기
(16)
[5주차] 페이징빈, Ajax
(0)
2. Spring Framework
(0)
빽's워드프레스
(1)
티스토리 관리
(1)
홈
태그
방명록
관리자
글쓰기
/
/
Model2 Architecture - (5) 회원수정
2019. 8. 3. 20:53
1. 회원수정 1)WebContent - update.jsp
<%@ page import = "model.ClientDTO" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
회원정보수정
<% ClientDTO clientDTO = (ClientDTO)session.getAttribute("clientDTO"); %>
아이디
비밀번호
이름
이메일
전화번호
주소
2)WebContent - update_result.jsp
<%@ page import = "model.ClientDTO" %> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
Insert title here
HOME
<% ClientDTO updateDTO = (ClientDTO)session.getAttribute("updateDTO"); %> 아이디 : <%=updateDTO.getClientId() %>
비밀번호 : <%=updateDTO.getClientPassword() %>
이름 : <%=updateDTO.getClientName() %>
주소 : <%=updateDTO.getClientAddress() %>
전화번호 : <%=updateDTO.getClientPhone() %>
2. Controller 1)src = controller.HandlerMapping.java에 update 추가
if(command.equals("update")) { c = new UpdateController();
2)src - controller.UpdateController.java
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 { System.out.println("enter to UpdateController()..."); HttpSession session = request.getSession(false); ClientDTO dto = (ClientDTO) session.getAttribute("clientDTO"); ClientDTO updateDTO = ClientDAO.getInstance().updateMemberInfo(dto); session.setAttribute("updateDTO", updateDTO); return "redirect:update_result.jsp"; } }
3. model 변경 1) src - model.ClientDAO.java에 updateMemberInfo 메소드 추가
public ClientDTO updateMemberInfo(ClientDTO clientDTO) throws SQLException { String ret = null; Connection con = null; PreparedStatement pstmt = null; ClientDTO updateDTO = 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()); System.out.println("update clientdto : " + clientDTO); int result = pstmt.executeUpdate(); if (result > 0) { System.out.println("success to update"); updateDTO = clientDTO; }else System.out.println("fail to update"); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { closeAll(pstmt, con); } return clientDTO; }
공유하기
게시글 관리
구독하기
개발자로가는길
'
1.JAVA Web Programming
>
[3주차]JSP+model2
' 카테고리의 다른 글
Model2 Architecture - (6) 회원탈퇴
(0)
2019.08.03
Model2 Architecture - (4) 로그아웃
(0)
2019.08.03
Model2 Architecture - (3) 로그인
(0)
2019.08.02
Model2 Architecture - (2) 회원조회
(0)
2019.08.01
Model2 Architecture - (1) 회원가입
(0)
2019.08.01
+ Recent posts
Powered by
Tistory
, Designed by
wallel
Rss Feed
and
Twitter
,
Facebook
,
Youtube
,
Google+
티스토리툴바