jspblog : userjoin
This commit is contained in:
@@ -4,6 +4,7 @@ import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class DB {
|
||||
|
||||
@@ -20,4 +21,13 @@ public class DB {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void close(Connection conn, PreparedStatement pstmt) {
|
||||
try {
|
||||
if (pstmt != null) pstmt.close();
|
||||
conn.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,34 @@
|
||||
package com.example.jspblog.domain.user;
|
||||
|
||||
import com.example.jspblog.config.DB;
|
||||
import com.example.jspblog.domain.user.dto.JoinReqDto;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class UserDao {
|
||||
|
||||
public void save() { // 회원 가입
|
||||
public int save(JoinReqDto dto) { // 회원 가입
|
||||
String sql = "INSERT INTO user(username, password, email, address, userRole, createDate) VALUES (?, ?, ?, ?, 'USER', now())";
|
||||
|
||||
Connection conn = DB.getConnection();
|
||||
PreparedStatement pstmt = null;
|
||||
if (conn != null) {
|
||||
try {
|
||||
pstmt = conn.prepareStatement(sql);
|
||||
pstmt.setString(1, dto.getUsername());
|
||||
pstmt.setString(2, dto.getPassword());
|
||||
pstmt.setString(3, dto.getEmail());
|
||||
pstmt.setString(4, dto.getAddress());
|
||||
int result = pstmt.executeUpdate();
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
DB.close(conn, pstmt);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void update() { // 회원수정
|
||||
|
||||
@@ -1,18 +1,25 @@
|
||||
package com.example.jspblog.service;
|
||||
|
||||
import com.example.jspblog.config.DB;
|
||||
import com.example.jspblog.domain.user.User;
|
||||
import com.example.jspblog.domain.user.UserDao;
|
||||
import com.example.jspblog.domain.user.dto.JoinReqDto;
|
||||
import com.example.jspblog.domain.user.dto.LoginReqDto;
|
||||
import com.example.jspblog.domain.user.User;
|
||||
import com.example.jspblog.domain.user.dto.UpdateReqDto;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class UserService {
|
||||
private final UserDao userDao;
|
||||
|
||||
// 회원가입, 회원수정, 로그인, 로그아웃, 아이디 중복체크
|
||||
|
||||
public UserService() {
|
||||
userDao = new UserDao();
|
||||
}
|
||||
|
||||
public int 회원가입(JoinReqDto dto) {
|
||||
|
||||
return -1;
|
||||
int result = userDao.save(dto);
|
||||
return result;
|
||||
}
|
||||
|
||||
public User 로그인(LoginReqDto dto) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@WebServlet(name = "user")
|
||||
@WebServlet("/user")
|
||||
public class UserController extends HttpServlet {
|
||||
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
doProcess(request, response);
|
||||
@@ -47,7 +47,12 @@ public class UserController extends HttpServlet {
|
||||
dto.setPassword(password);
|
||||
dto.setEmail(email);
|
||||
dto.setAddress(address);
|
||||
userService.회원가입(dto);
|
||||
int result = userService.회원가입(dto);
|
||||
if (result == 1) {
|
||||
response.sendRedirect("index.jsp");
|
||||
} else {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,25 +3,25 @@
|
||||
<%@ include file="../layout/header.jsp"%>
|
||||
|
||||
<div class="container">
|
||||
<form action="/action_page.php">
|
||||
<form action="${pageContext.request.contextPath}/user?cmd=join" method="post">
|
||||
<div class="form-group">
|
||||
<label for="username">Username:</label>
|
||||
<input type="text" class="form-control" placeholder="Enter username" id="username">
|
||||
<input name="username" type="text" class="form-control" placeholder="Enter username" id="username" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="pwd">Password:</label>
|
||||
<input type="password" class="form-control" placeholder="Enter password" id="pwd">
|
||||
<input name="password" type="password" class="form-control" placeholder="Enter password" id="pwd" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="email">Email:</label>
|
||||
<input type="email" class="form-control" placeholder="Enter email" id="email">
|
||||
<input name="email" type="email" class="form-control" placeholder="Enter email" id="email" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="address">Address:</label>
|
||||
<input type="text" class="form-control" placeholder="Enter address" id="address">
|
||||
<input name="address" type="text" class="form-control" placeholder="Enter address" id="address" required>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">회원가입 완료</button>
|
||||
|
||||
Reference in New Issue
Block a user