- MemberFrontController.java
package com.itwillbs.member.action;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class MemberFrontController extends HttpServlet{
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("MemberFrontController doGet()");
doProcess(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("MemberFrontController doPost()");
doProcess(request, response);
}
protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("MemberFrontController doProcess()");
System.out.println("뽑은 가상주소 : "+request.getServletPath());
String sPath=request.getServletPath();
ActionForward forward = null;
Action action=null;
if(sPath.equals("/MemberInsertForm.me")) {
System.out.println("가상주소 /MemberInsertForm.me => 실제페이지 member/insertForm.jsp 이동");
forward = new ActionForward();
forward.setPath("member/insertFrom.jsp");
forward.setRedirect(false);
}else if(sPath.equals("/MemberInsertPro.me")) {
System.out.println("가상주소 /MemberInsertPro.me => 실제자바파일 연결");
action = new MemberInsertPro();
try {
forward=action.execute(request, response);
} catch (Exception e) {
}
} else if (sPath.equals("/MemberLoginForm.me")) {
forward = new ActionForward();
forward.setPath("member/loginForm.jsp");
forward.setRedirect(false);
} else if (sPath.equals("/MemberLoginPro.me")) {
LoginPro loginPro = new LoginPro();
try {
loginPro.execute2(request, response);
} catch (Exception e) {
e.printStackTrace();
}
} else if(sPath.equals("/MemberMain.me")) {
forward = new ActionForward();
forward.setPath("member/main.jsp");
forward.setRedirect(false);
}
if(forward != null) {
if(forward.isRedirect()==true) {
response.sendRedirect(forward.getPath());
}else{
RequestDispatcher dispatcher=
request.getRequestDispatcher(forward.getPath());
dispatcher.forward(request, response);
}
}
}
}
package com.itwillbs.member.action;
import java.sql.Timestamp;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.itwillbs.member.db.MemberDAO;
import com.itwillbs.member.db.MemberDTO;
public class InsertPro {
public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception{
System.out.println("InsertPro execute()");
request.setCharacterEncoding("utf-8");
String id=request.getParameter("id");
String pass=request.getParameter("pass");
String name=request.getParameter("name");
Timestamp date=new Timestamp(System.currentTimeMillis());
MemberDTO dto=new MemberDTO();
System.out.println("MemberDTO 바구니 주소 : "+dto);
dto.setId(id);
dto.setPass(pass);
dto.setName(name);
dto.setDate(date);
MemberDAO dao=new MemberDAO();
System.out.println("MemberDAO 주소 : "+dao);
dao.insertMember(dto);
}
}
package com.itwillbs.member.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.itwillbs.member.db.MemberDAO;
import com.itwillbs.member.db.MemberDTO;
public class LoginPro {
public void execute2(HttpServletRequest request, HttpServletResponse response){
System.out.println("LoginPro execute2()");
String id=request.getParameter("id");
String pass=request.getParameter("pass");
MemberDAO dao=new MemberDAO();
MemberDTO dto=dao.userCheck(id, pass);
if(dto !=null){
HttpSession session = request.getSession();
session.setAttribute("id", id);
}else{
}
return;
}
}
package com.itwillbs.member.action;
public class ActionForward {
private String path;
private boolean isRedirect;
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public boolean isRedirect() {
return isRedirect;
}
public void setRedirect(boolean isRedirect) {
this.isRedirect = isRedirect;
}
}
package com.itwillbs.member.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public interface Action {
public ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws Exception;
}
package com.itwillbs.member.action;
import java.sql.Timestamp;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.itwillbs.member.db.MemberDAO;
import com.itwillbs.member.db.MemberDTO;
public class MemberInsertPro implements Action {
@Override
public ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
System.out.println("InsertPro execute()");
request.setCharacterEncoding("utf-8");
String id=request.getParameter("id");
String pass=request.getParameter("pass");
String name=request.getParameter("name");
Timestamp date=new Timestamp(System.currentTimeMillis());
MemberDTO dto=new MemberDTO();
System.out.println("MemberDTO 바구니 주소 : "+dto);
dto.setId(id);
dto.setPass(pass);
dto.setName(name);
dto.setDate(date);
MemberDAO dao=new MemberDAO();
System.out.println("MemberDAO 주소 : "+dao);
dao.insertMember(dto);
ActionForward forward = new ActionForward();
forward.setPath("MemberLoginForm.me");
forward.setRedirect(true);
return forward;
}
}