반응형
User
package jspmodel1.vo;
public class UserVO {
private String uno;
private String uid;
private String upw;
private String uname;
private String uphone;
private String uemail;
private String rdate;
private String ustate;
private String uauthor;
public String getUno() { return uno; }
public String getUid() { return uid; }
public String getUpw() { return upw; }
public String getUname() { return uname; }
public String getUphone() { return uphone; }
public String getUemail() { return uemail; }
public String getRdate() { return rdate; }
public String getUstate() { return ustate; }
public String getUauthor() { return uauthor; }
public void setUno(String uno) { this.uno = uno; }
public void setUid(String uid) { this.uid = uid; }
public void setUpw(String upw) { this.upw = upw; }
public void setUname(String uname) { this.uname = uname; }
public void setUphone(String uphone) { this.uphone = uphone; }
public void setUemail(String uemail) { this.uemail = uemail; }
public void setRdate(String rdate) { this.rdate = rdate; }
public void setUstate(String ustate) { this.ustate = ustate; }
public void setUauthor(String uauthor) { this.uauthor = uauthor; }
}
modify.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="jspmodel1.*" %>
<%
//bean에 대입할 파라미터들의 인코딩 타입부터 UTF-8로 수정한다
request.setCharacterEncoding("UTF-8");
%>
<jsp:useBean class="jspmodel1.vo.UserVO" id="user" />
<jsp:setProperty name="user" property="*"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>회원정보 수정하기</title>
</head>
<body>
<h2>회원정보 수정하기</h2><hr>
<!--
사용자에게 아이디,비밀번호,이름,연락처,이메일 정보를 입력받은 후
입력한 아이디의 기타 정보들을 수정하는 기능을 구현하세요
이때 입력정보는 bean을 사용합니다
-->
<form action="modify.jsp">
<input type="text" name="uid" placeholder="아이디"><br>
<input type="password" name="upw" placeholder="비밀번호"><br>
<input type="submit" value="회원정보확인">
</form>
<%
Connection conn = null; //DB 연결
PreparedStatement psmt = null; //SQL 등록 및 실행. 보안이 더 좋음!
ResultSet rs = null; //조회 결과를 담음
String uid = "";
String upw = "";
String uname = "";
String uphone = "";
String uemail = "";
//try 영역
try{
conn = DBConn.conn();
String sql = "select * from user where uid=? and upw=?";
psmt = conn.prepareStatement(sql);
psmt.setString(1, user.getUid());
psmt.setString(2, user.getUpw());
rs = psmt.executeQuery();
if(rs.next()){
uid = rs.getString("uid");
upw = rs.getString("upw");
uname = rs.getString("uname");
uphone = rs.getString("uphone");
uemail = rs.getString("uemail");
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(rs != null) rs.close();
if(psmt != null) psmt.close();
if(conn != null) conn.close();
}
%>
<form action="modifyOk.jsp" method="post">
<input type="hidden" name="uid" value="<%= uid %>">
<input type="password" name="upw" placeholder="비밀번호" value="<%= upw%>"><br>
<input type="text" name="uname" placeholder="이름" value="<%= uname%>"><br>
<input type="text" name="uphone" placeholder="연락처" value="<%= uphone%>"><br>
<input type="email" name="uemail" placeholder="이메일" value="<%= uemail%>"><br>
<input type="submit" value="수정하기">
<input type="reset" value="취소">
</form>
</body>
</html>
modifyOk.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<%@ page import="jspmodel1.*" %>
<%
//bean에 대입할 파라미터들의 인코딩 타입부터 UTF-8로 수정한다
request.setCharacterEncoding("UTF-8");
%>
<jsp:useBean class="jspmodel1.vo.UserVO" id="user1" />
<jsp:setProperty name="user1" property="*"/>
<%
if(request.getMethod().equals("GET")){
response.sendRedirect("index.jsp");
}
Connection conn = null;
PreparedStatement psmt = null;
try{
conn = DBConn.conn();
String sql = "update user set "
+ "upw=?, uname=?, uphone=?, uemail=? where uid=?";
psmt = conn.prepareStatement(sql);
psmt.setString(1, user1.getUpw());
psmt.setString(2, user1.getUname());
psmt.setString(3, user1.getUphone());
psmt.setString(4, user1.getUemail());
psmt.setString(5, user1.getUid());
int result = psmt.executeUpdate();
if(result > 0){
//등록완료
%>
<script>
alert("회원정보가 변경되었습니다");
location.href = "<%= request.getContextPath() %>/index.jsp";
</script>
<%
}
}catch(Exception e){
e.printStackTrace();
out.print(e.getMessage());
}finally{
DBConn.close(psmt, conn);
}
%>
반응형
'Java' 카테고리의 다른 글
[Servlet] 로그인한 회원의 회원 정보 조회 (0) | 2024.10.10 |
---|---|
[Servlet] 로그인 처리 (0) | 2024.10.09 |
[Servlet] 모델2 MVC (4) | 2024.10.07 |
[JSP] 모델1로 회원가입하기 (0) | 2024.10.06 |
[JSP]모델 1 (0) | 2024.10.05 |