DoR@Hee의 끄적끄적

JSP 회원정보 변경 - 비밀번호 본문

개발/WEB개발

JSP 회원정보 변경 - 비밀번호

DoR@Hee 2019. 1. 31. 18:27

VIEW - member_modify.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
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
    
<% String uId = (String)session.getAttribute("uId"); %>
<!DOCTYPE html>
<html>
<head>
    <script charset="utf-8" type="text/javascript" src="Check.js?ver=1.1"></script>
    <link rel="stylesheet" href="style2.css?ver=1.2">
    <link href="https://fonts.googleapis.com/css?family=Gamja+Flower&amp;subset=korean" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Mukta" rel="stylesheet">
    <script>
    </script>
</head>
<body>
    <form action="modify_member.do" method="post" name="mod">
        <div id="member_modify">
            <input type="hidden" name="uId" value="<%=uId%>">
            <p id="writer_font">정보수정 페이지</p><br>
            <span>비밀번호</span>: <input type="password" name="uPassword" id="m_password"><br>
            <span>비밀번호 확인:</span> <input type="password" name="uPassword2" id="m_password2"><br>
            <button type="button" class="btn" id="member_modify_btn" onclick="modify();">변경</button>
        </div>
    </form>    
</body>
</html>
cs

Model - UDao.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
    public void ModifyMember(String uId, String uPassword) { //정보 수정을 위함
        Connection con = null;
        PreparedStatement pstmt = null;
        
        try {
            String query = "update members set pw = ? where id = ?";
            Class.forName(driver);
            con = DriverManager.getConnection(url, user, password);
            pstmt=con.prepareStatement(query);
            pstmt.setString(1, uPassword);
            pstmt.setString(2, uId);
            
            pstmt.executeQuery();
        } catch(Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if(con != null) con.close();
                if(pstmt != null) pstmt.close();
            } catch(Exception e2) {
                e2.printStackTrace();
            }
        }
    }
cs

Command

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package com.javalec.ex.command;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import com.javalec.ex.dao.*;
 
public class UModifyMemberCommand implements BCommand{
    
    public void execute(HttpServletRequest requset, HttpServletResponse response) {
        String uId = requset.getParameter("uId");
        String uPassword = requset.getParameter("uPassword");
        
         UDao dao = UDao.getInstance();
         dao.ModifyMember(uId,uPassword);
         
         
         
    }
 
}
 
cs

Controller

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
    private void actiondo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        
        request.setCharacterEncoding("EUC-KR");
        
        String viewPage = null// 페이지 리다이렉트
        BCommand command = null// command 저장
        
        String url = request.getRequestURI(); //  ex)http://localhost/board/test.jsp >> board/test.jsp
        String conPath = request.getContextPath(); // ex) http://localhost/board/test.jsp >> /test.jsp
        String con = url.substring(conPath.length());    
        if(con.equals("/modify_member.do")) {
            command = new UModifyMemberCommand();
            command.execute(request,response);
            viewPage="main2.jsp";
        }
        
        RequestDispatcher dispatcher = request.getRequestDispatcher(viewPage);
        dispatcher.forward(request, response);
        
    }
cs


'개발 > WEB개발' 카테고리의 다른 글

JSP 글 삭제 기능 만들기  (0) 2019.01.31
JSP 조회수 기능 만들기  (0) 2019.01.31
JSP 글 수정 만들기  (0) 2019.01.31
JSP 로그아웃 만들기  (0) 2019.01.31
JSP 글 보기 만들기  (0) 2019.01.31
Comments