안녕하세요.
https://blog.naver.com/sysysy0302 여니입니다 :)
MemberUpdatePwdController
/**
* Servlet implementation class MemberUpdatePwdController
*/
@WebServlet("/updatePwd.me")
public class MemberUpdatePwdController extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public MemberUpdatePwdController() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
String userId = request.getParameter("userId");
String userPwd = request.getParameter("userPwd");
String updatePwd = request.getParameter("updatePwd");
Member updateMember = new MemberService().updatePwdMember(userId, userPwd, updatePwd);
// 실패시 => 마이페이지로 url재요청 ,
// 메세지내용 : 비밀번호 변경에 실패했습니다.
HttpSession session = request.getSession();
if(updateMember == null) {
session.setAttribute("alertMsg", "비밀번호 변경에 실패했습니다.");
}else {
session.setAttribute("alertMsg", "비밀번호가 변경되었습니다.");
session.setAttribute("loginUser", updateMember);
}
response.sendRedirect(request.getContextPath()+"/update.me");
// 성공시 => 마이페이지로 url재요청 ,
// 메세지 내용 : 성공적으로 비밀번호가 변경되었습니다.
// 변경된 회원정보 session에 등록
}
MemberService
public Member updatePwdMember(String userId, String userPwd, String updatePwd ) {
Connection conn = getConnection();
int result = new MemberDao().updatePwdMember(conn, userId, userPwd, updatePwd);
Member updateMember = null;
if(result > 0) {
commit(conn);
updateMember = new MemberDao().selectMember(conn, userId);
}else {
rollback(conn);
}
close(conn);
return updateMember;
}
MemberDao
public int updatePwdMember(Connection conn, String userId, String userPwd, String updatePwd) {
int result = 0;
PreparedStatement pstmt = null;
String sql = prop.getProperty("updatePwdMember");
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, updatePwd);
pstmt.setString(2, userId);
pstmt.setString(3, userPwd);
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(pstmt);
}
return result;
}
member-mapper.xml
<entry key="updatePwdMember">
UPDATE MEMBER
SET USER_PWD = ?
,MODIFY_DATE = SYSDATE
WHERE USER_ID = ? AND USER_PWD =?
</entry>
'⋆ 。゜☁︎ 。⋆ 。゜☾゜。⋆⋆ 。゜☁︎ 。⋆ 。゜☾゜。⋆ > JSP' 카테고리의 다른 글
JSP - JSP와 스크립틀릿, 내장객체 종류 (0) | 2023.07.12 |
---|---|
이클립스 Servlet (doPost 방식-delete문-update) (1) | 2023.07.05 |
이클립스 Servlet (doPost 방식-update) (0) | 2023.07.05 |
이클립스 Servlet (doPost 방식-insert) (0) | 2023.07.05 |
JSP/ECLIPSE - 이클립스 Servlet 환경설정, 아파치톰캣 서버등록 (0) | 2023.06.26 |