1. include/nav.jsp만들기
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<nav>
<c:choose>
<c:when test="${empty sessionScope.principal}">
<a href="/apple/member?cmd=loginForm">로그인</a>
<a href="/apple/member?cmd=joinForm">회원가입</a>
</c:when>
<c:otherwise>
<a href="/apple/member?cmd=updateForm">회원정보</a>
<a href="/apple/member?cmd=logout">로그아웃</a>
</c:otherwise>
</c:choose>
</nav>
2. 모든 jsp(view) 페이지 수정
<nav></nav> 부분에 아래 문구 삽입하기
<%@include file="../include/nav.jsp" %>
3. MemberDao.java
package com.cos.apple.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import com.cos.apple.db.DBConn;
public class MemberDao {
private Connection conn;
private PreparedStatement pstmt;
private ResultSet rs;
public int 회원가입(String username, String password, String email) {
try {
String sql = "INSERT INTO member(id, username, password, email, createDate) VALUES(member_seq.nextval, ?,?,?, sysdate)";
conn = DBConn.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, username);
pstmt.setString(2, password);
pstmt.setString(3, email);
return pstmt.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
return -1;
}
}
4. MemberJoinProc.java
package com.cos.apple.action.member;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.cos.apple.action.Action;
import com.cos.apple.dao.MemberDao;
public class MemberJoinProcAction implements Action{
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
String email = request.getParameter("email");
MemberDao memberDao = new MemberDao();
int result = memberDao.회원가입(username, password, email);
if(result == 1) {
response.sendRedirect("member/loginForm.jsp");
}else {
response.sendRedirect("member/joinForm.jsp");
}
}
}
'jsp 프로젝트 V2 post' 카테고리의 다른 글
JSP게시판 만들기 10강 - 글쓰기 (0) | 2020.06.19 |
---|---|
JSP게시판 만들기 7강 - 로그인 (0) | 2020.06.19 |
JSP게시판 만들기 5강 - 모델 만들기 (0) | 2020.06.18 |
JSP게시판 만들기 4강 - 화면구현 (0) | 2020.06.18 |
JSP게시판 만들기 3강 - MVC세팅하기 (0) | 2020.06.18 |