내용

글번호 1196
작성자 heojk
작성일 2023-03-16 09:35:11
제목 3일차 요약
내용 3일차 정리 Spring Web MVC web.xml 파일을 이해 Listener와 context parameter 컨텍스트가 초기화될 때 실행되는 리스너가 context-param을 읽어 빈을 생성하고 의존성 주입을 해줌 <- core container에 로드 DispatcherServlet 서블릿 초기화 파라미터를 읽어 빈을 생성하고 의존성 주입 <- 스프링 web container에 로드 (컨트롤러, 뷰리졸버, 리소스, 인터셉터 등) M : 모델(데이터를 저장하는 객체), V : 화면 출력(jsp), C : 제어로직(java) 컨트롤러는... @Controller <- 빈으로 만들어 지도록 public class EmpController { @Autowired <-- 의존성 주입 IEmpService empService; @RequestMapping("/url") <-- url은 반드시 소문자로 작성, /로 시작 public String handlerMethod(Model model) { // biz() 호출 model.addAttribute("key", "value"); <--request에 저장 or 파라미터로 전송 return "viewname"; //"redirect:/url?key=value" } - 파라미터는 어떻게 보낼까요? @RequestParam 요청 파라미터 http:/localhost/myapp/empcount?deptid=50 메서드 파라미터 public String getEmpCount( @RequestParam(name="deptid", required=false, defaultValue="0") int departmentId, Model... - @PathVariable Servlet/JSP 서블릿 : 컨트롤러를 만드는 용도였음 HttpServletRequest - request : 요청 파라미터, 헤더, URL, IP HttpServletResponse - response : 응답객체, encodeURL, sendRedirect PrintWriter - out : 출력, println ServletConfig - config : 서블릿 초기화 파라미터를 읽을 때, init(ServletConfig) ServletContext - application : 컨텍스트 초기화 파라미터를 읽을 때 ServletContextListener인터페이스의 contextInitialized(ServeltContextEvent) ServletContext context = sce.getServletContext(); HttpSession - session : 로그인/로그아웃 세션 무효화 invalidate() 즉시 무효화 setMaxInactiveInterval(초) web.xml 파일에 timeout을 분단위로 설정 JSP는 .java로 변환된 후 .class 파일로 컴파일 되고 실행됨 <%@ ... %> directive, page, include, taglib <%@ page contentType="text/html;utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%! ... %> declaration, 변수, 메서드 선언 <%= ... %> expression, 출력 <% out.print(변수명); %> <%= 변수명 %> <% ... %> scriptlet, 자바코드 JSP에 자바코드를 포함하지 않으려면... EL : 데이터 출력 용도 ${ } JSTL : core 라이브러리는 제어로직을 작성