이전 서블릿 ⇒ webContent에 리소스가 있기 때문에 외부에서 접근 제한이 없음 webContent - WEB-INF - *.jsp - image - *.png - css - *.css - js - *.js 스프링 ⇒ WEB-INF에 리소스가 있기 때문에 외부에서 접근 할 수 없다. (보안) webapp - WEB-INF - image - *.png - css - *.css - js - *.js - views - *.jsp ⇒ JSP에서 리소스(image, css, js)에 접근할 수 있도록 추가 설정이 필요하다. ⇒ servlet-context.xml에 설정 https://docs.spring.io/spring-framework/docs/5.2.25.RELEASE/spring-framework-r..
Filter 서블릿 전 및 후에서 가로채기 했음 implements Filter 3가지 메서드 재정의 init(){} doFilter(){ } destroy() ⇒ 인터페이스니까 세가지를 다 구현해야함 3. web.xml에 등록 … /* HandlerInterceptorAdapter Controller 전 / 후 / jsp 화면처리 후에서 가로채기 가능 extends HandlerInterceptorAdapter 필요한 메서드만 재정의 a.가로채기 boolean preHandle(){} b.가로채기 void postHandle(){} c.가로채기 void afterCompletion(){} ⇒ 인터페이스가 아니니까 필요한 것만 선택해서 구현하면 됨 servlet-context.xml에 빈으로 등록 ( 또..
이전 서블릿 request scope session scope application scope 스프링 request scope flash scope ==========⇒ redirect 했는데 target에서 값을 딱 한번만 사용할 수 있다. session scope application scope 💡 기존 redirect 에서는 Model의 값을 tartget 사용 못 함 @RequestMapping("/aaa") m.addAttribute(key,value); return "redirect:target"; } flash scope의 redirect ⇒ RedirectAttributes 값을 target 사용 가능 public String xxx(RedirectAttributes m) { m.addFl..
이전 서블릿 redirect response.sendRedirect(”target”); 화면 URL 변경 request scope에 저장된 데이터는 target에서 사용불가 forward request.getRequestDispatcher(”target”).forward(request, response); 화면 URL 변경 안됨 request scope에 저장된 데이터는 target에서 사용 가능 스프링 redirect public String xxx( ) { return “redirect:target”; } forward public String xxx( ) { return “forward:target”; } redirect forward redirect, forward로 값 가져오기
@RequestMapping("/a") public String xxx( ) { } view정보o Model정보x @RequestMapping("/a") public String xxx(Model m) { } view정보o Model정보o @RequestMapping(”/a”) public ModelAndView xxx( ) { } view정보o Model정보o @RequestMapping(”/a”) public @ModelAttribute("key") LoginDTO xxx( ) { } view정보x Model정보o Spring이 뷰를 유추해서 찾음 ( 요청맵핑값으로 뷰를 찾음) (a.jsp) (/WEB-INF/views/a.jsp) @RequestMapping(”/a”) public String xx..
이전 서블릿 request scope에 저장 request.setAttribute(key, value); session scope에 저장 HttpSession session = request.getSession(); session.setAttribute(key, value); application scope에 저장 ServletContext application = getServletContext(); application.setAttribute(key, value); 스프링 request scope에 저장 public String xxx (Model m) { m.addAttribute(key, value); } session scope에 저장 public String xxx(HttpSession ses..
모델 생성하는 방법 = jsp에서 보여줄 데이터 생성 방법 Model이란? Model은 HashMap 형태를 갖고 있으며 key-value 값을 가지고 있다. addAttribute()와 같은 기능을 통해 모델에 원하는 속성과 값을 주어 전달할 view에 데이터를 전달할 수 있다. Spring에서 Controller의 메서드를 작성할 때는 특별하게 Model이라는 타입을 파라미터로 지정할 수 있다. 그러면 Spring은 특별하게 Model타입의 객체를 만들어서 메서드에 주입하게 되는데, 이 Model객체는 컨트롤러에서 생성된 데이터를 담아서 JSP에 전달하는 역할을 하게 된다. 그러므로 이를 이용해서 JSP와 같은 View로 전달해야 하는 데이터를 담아서 보낼 수 있다. 브라우저 ——> Dispatche..