반응형
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; }
}
join.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>회원가입</title>
</head>
<body>
<h2>회원가입</h2><hr>
<!--
board 데이터베이스의 user 테이블에 회원가입이 가능하도록 bean을 사용하여 기능을 완성
1. bean을 생성할 수 있는 클래스를 선언
2. 회원가입 페이지를 디자인한다
3. bean을 활용하여 회원가입 기능을 구현한다
-->
<form action="joinOk.jsp" method="post">
<input type="text" name="uid" placeholder="아이디"><br>
<input type="password" name="upw" placeholder="비밀번호"><br>
<input type="password" name="upwcheck" placeholder="비밀번호확인"><br>
<input type="text" name="uname" placeholder="이름"><br>
<input type="text" name="uphone" placeholder="연락처"><br>
<input type="email" name="uemail" placeholder="이메일"><br>
<input type="submit" value="회원가입">
<input type="reset" value="취소">
</form>
</body>
</html>
joinOk.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="*"/>
<%-- <jsp:setProperty name="user1" property="uid" param="uid"/>
<jsp:setProperty name="user1" property="upw" param="upw"/>
<jsp:setProperty name="user1" property="uname" param="uname"/>
<jsp:setProperty name="user1" property="uphone" param="uphone"/>
<jsp:setProperty name="user1" property="uemail" param="uemail"/> --%>
<%
if(request.getMethod().equals("GET")){
response.sendRedirect("join.jsp");
}
Connection conn = null;
PreparedStatement psmt = null;
try{
conn = DBConn.conn();
String sql = "insert into user (uid,upw,uname,uphone,uemail) "
+ " values (?,?,?,?,?) ";
psmt = conn.prepareStatement(sql);
psmt.setString(1, user1.getUid());
psmt.setString(2, user1.getUpw());
psmt.setString(3, user1.getUname());
psmt.setString(4, user1.getUphone());
psmt.setString(5, user1.getUemail());
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' 카테고리의 다른 글
[JSP] 회원정보 조회하고 수정하기 (0) | 2024.10.08 |
---|---|
[Servlet] 모델2 MVC (4) | 2024.10.07 |
[JSP]모델 1 (0) | 2024.10.05 |
[Java] 람다식 (2) | 2024.08.27 |
[Java] Map (0) | 2024.08.25 |