<HandlerMapping>
package com.smhrd.frontcontroller;
import java.util.HashMap;
import com.smhrd.controller.AccController;
import com.smhrd.controller.Controller;
import com.smhrd.controller.JoinController;
import com.smhrd.controller.LoginController;
import com.smhrd.controller.LogoutController;
import com.smhrd.controller.MemberlistController;
import com.smhrd.controller.UlocationController;
import com.smhrd.controller.UseController;
import com.smhrd.controller.UsinglistController;
import com.smhrd.controller.ViewBlackboxController;
import com.smhrd.controller.ViewHlocationController;
import com.smhrd.controller.FAQController;
import com.smhrd.controller.ViewJoinController;
import com.smhrd.controller.ViewLoginController;
import com.smhrd.controller.ViewMainController;
import com.smhrd.controller.ViewUlocationController;
import com.smhrd.controller.ViewUseController;
import com.smhrd.dao.moduleDAO;
public class HandlerMapping {
private HashMap<String, Controller> mappings;
public HandlerMapping() {
mappings=new HashMap<String, Controller>();
mappings.put("/join.do", new JoinController());
mappings.put("/viewMain.do", new ViewMainController());
mappings.put("/viewJoin.do", new ViewJoinController());
mappings.put("/viewLogin.do", new ViewLoginController());
mappings.put("/login.do", new LoginController());
mappings.put("/memberlist.do", new MemberlistController());
mappings.put("/faq.do", new FAQController());
// mappings.put("/use.do", new UseController());
mappings.put("/viewUse.do", new ViewUseController());
mappings.put("/viewUlocation.do", new ViewUlocationController());
mappings.put("/logout.do", new LogoutController());
mappings.put("/viewHlocation.do", new ViewHlocationController());
mappings.put("/acc.do", new AccController());
mappings.put("/usinglist.do", new UsinglistController());
mappings.put("/viewBlackbox.do" , new ViewBlackboxController()) ;
}
public Controller getController(String command) {
return mappings.get(command);
}
}
<MemberFrontController>
package com.smhrd.frontcontroller;
import java.io.IOException;
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 com.smhrd.controller.Controller;
@SuppressWarnings("serial")
@WebServlet("*.do")
public class MemberFrontController extends HttpServlet {
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String reqUrl = request.getRequestURI();
String ctx = request.getContextPath();
String command = reqUrl.substring(ctx.length());
Controller controller = null;
String view = null;
HandlerMapping mappings=new HandlerMapping();
controller=mappings.getController(command);
view=controller.execute(request, response);
if (view != null) {
if (view.indexOf("redirect:/") != -1) {
response.sendRedirect(view.split(":/")[1]); // redirect:/boardList.do
} else {
RequestDispatcher rd = request.getRequestDispatcher(ViewResolver.makeView(view));
rd.forward(request, response);
}
}
}
}
<ViewResolver>
package com.smhrd.frontcontroller;
public class ViewResolver {
public static String makeView(String viewname) {
return "appkit-landing-v2.3/"+viewname+".jsp";
}
}
'2차 프로젝트' 카테고리의 다른 글
.JSP 파일 코드 (0) | 2022.07.22 |
---|---|
아두이노 Module 코드 (0) | 2022.07.22 |
Domain 코드 (0) | 2022.07.22 |
DAO 코드 (0) | 2022.07.22 |
Controller 코드 (0) | 2022.07.22 |