1. FrontController
package com.smhrd.frontcontroller;
import java.io.IOException;
import java.net.URLEncoder;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.DefaultFileRenamePolicy;
import com.smhrd.command.Command;
import com.smhrd.controller_class.DeleteBoardService;
import com.smhrd.controller_class.DeleteService;
import com.smhrd.controller_class.JoinService;
import com.smhrd.controller_class.LoginService;
import com.smhrd.controller_class.LogoutService;
import com.smhrd.controller_class.UpdateService;
import com.smhrd.controller_class.WriterBoardServce;
import com.smhrd.model.BoardDAO;
import com.smhrd.model.BoardVO;
import com.smhrd.model.DAO;
import com.smhrd.model.MemberVO;
@WebServlet("*.do") // .do라는 확장자를 갖고 있다면 frontcontroller로 오게 만드는 것
public class ForntController extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println("[FrontController]");
// 어느 서블릿으로 요청이 들어왔는지 확인
String uri = request.getRequestURI();
// System.out.println(uri);
// 프로젝트이름
String path1 = request.getContextPath();
// System.out.println(path);
// 요청들어온 servlet이름만 확인
// substring : 문자열 자르는 함수
// substring(start) : start위치부터 끝까지 문자열 자르기
String reqURI = uri.substring(path1.length() + 1);
System.out.println(reqURI);
request.setCharacterEncoding("UTF-8");
String moveURL = "";
Command sc = null;
if (reqURI.equals("JoinService.do")) {
sc = new JoinService();
} else if (reqURI.equals("LoginService.do")) {
sc = new LoginService();
} else if (reqURI.equals("LogoutService.do")) {
sc = new LogoutService();
} else if (reqURI.equals("WriterBoardService.do")) {
sc = new WriterBoardServce();
} else if (reqURI.equals("UpdateService.do")) {
sc = new UpdateService();
} else if (reqURI.equals("DeleteService.do")) {
sc = new DeleteService();
} else if (reqURI.equals("DeleteBoardService.do")) {
sc = new DeleteBoardService();
}
moveURL = sc.execute(request, response);
RequestDispatcher rd = request.getRequestDispatcher(moveURL);
rd.forward(request, response);
}
}