2022.09.26

Jimin·2022년 9월 27일
0

비트캠프

목록 보기
45/60
post-thumbnail
  • 서블릿 프로그래밍
    • JSP로 만드는 서블릿 클래스의 규격
  • board-app 프로젝트 수행
      1. JSP를 이용하여 출력문을 자동으로 생성하기: MVC 모델1(계속)
      1. JSP에 있는 자바 코드를 Servlet으로 분리하기: MVC 모델2
      1. OGNL 표기법으로 객체 프로퍼티를 좀 더 쉽게 다루기: EL 문법 사용

MVC Model

Controller

  • 요청을 처리하기 위해 요청 정보를 가공하여 적절한 서비스 객체와 DAO 객체를 실행한다.
  • 응답을 처리하기 위해 응답 데이터를 가공하여 출력을 담당하고 객체를 실행한다.
  • Servlet

View

  • Controller가 준비한 데이터를 가지고 출력 UI 생성한다.
  • JSP

Model

  • 요청/응답에 필요한 작업을 수행한다.
  • DAO, Domain

MVC Model2

MVC Model1에서는 JSP가 Controller와 View 역할을 모두 했었는데 MVC Model2에서는 그 역할을 분리시켰다.


include/forward

include

forward


게시글 목록 조회: MVC Model2


게시글 목록 조회: MVC Model2
→ 오류발생!


JSP Built-in 객체

JSP 파일을 가지고 서블릿 자바 코드를 생성할 때 기본으로 준비하는 객체

-jspService(HttpServletRequest request,
			HttpServletResponse response) {
                  PageContent pageContent = ----;
                  HttpSession httpSession = ----;
                  ServletContext servletContext = ----;
                  ServletConfig config = ----;
                  JSPWriter out = ----;
                  Object page = this; (현재객체)
                  Throwable exception = ----;

Refresh와 Redirect

Refresh


Redirect


OGNL 표기법으로 객체 프로퍼티를 좀 더 쉽게다루기:
EL(Expression Language)

EL(Expression Language)

OGNL 표기법을 사용하여 객체의 프로퍼티 값을 조회한다.

OGNL 표기법

Object Graph Navigation Language
(객체 연결 점을 따라 이동하면서 값을 조회하는 문법)

필드와 프로퍼티

class Board{
	String tle; // field
    
    
[Property
    void setTitle(String title){ // setter
    	this.tle = title;
    }
    String getTitle() { // getter
    	return this.tle;
    }
 ]
${객체.프로퍼티.프로퍼티.프로퍼티. ...}
${board.title}

필드명: tle
프로터피명: setTitle(){} → title

EL의 기본 객체:

  • applicationScope (ServletContext 보관소)
  • sessionScope (HttpSession 보관소)
  • requestScope (ServletRequest 보관소)
  • pageScope (PageContext, JspContext 보관소)
application.getAttribute("board")
→ ${applicationScope.board}

session.getAttribute("board")
⇒ ${sessionScope.board}

request.getAttribute("board")
⇒ ${requestSope.board}

pageContext.getAttribute("board")
⇒ ${pageScope.board}

만약, Scope을 생략하면 pageContext → ServletRequest → HttpSession → ServletContext 순으로 보관소에서 해당 필드를 찾는다.


063. EL 문법 도입:
객체 프로퍼티 값 추출을 더 쉽고 간결하게

<%
Board board = (Board)request.getAttribute("board");
5>
<%=board.title%>

${requestScope.board.title}
profile
https://github.com/Dingadung

0개의 댓글