MVC pattern
model2 Architecture
--model
>>업무 처리 로직(서비스)
>> DAO
>> DTO
>>Java class(java bean component 포함)
--view
>>화면 로직
>>JSP(html, css, js)
--controller
>>요청~응답 제어
>> Servlet
view에서 요청한 데이터 엑세스를 하기위해 동작 메서드로 보내는 역할
JSP <%기호 속성명 ="속성값" 속성명='속성값' %>
>>주석태그
>> <!--html 주석 --> : 응답시 포함 주석(소스보기 가능, 페이지 배치 관련 주석)
>> <% //한줄 주석 %> <% /* 여러 줄 주석 */ %> : .jsp=> .java 변환 시에 포함
>> < %-- jsp주석 --%> : jsp페이지에서만 보기 가능한 주석
-- <%! %>
>> 멤버변수, 메서드, 라이프사이클메서드 재정의
>> declaration tag(정의어 태그)
--<%@ page %>, <%@ taglib %>, <%@ include %>
>> directive tag 지시어 태그
--<%= expression %>
>>expression tag : 수식 수행결과 출력
>> 서비스메서드 내부 자동 변환
>> _jspService(){ 서비스 자바 코드 변환; }
-- <% 자바 서비스코드; %>
>> scriptlet tag
>> jsp 서비스 내부 자동 변환
-- JSP 내장객체 (expression, scriptlet )
>> _jspService(){ } 메서드 내부에서 사용가능한 객체
>> .jsp 페이지가. java 변환시에 자동 제공되는 객체
>> out : JspWriter
>> request : HttpServletRequest
>> session : HttpSession
>> application : ServletContent
>> exception : Throwable
EL(Expression Language)
-- 기본형식 : ${exprssion}
-- 수식결과 출력
>> ${ 5 * 3 }
>>${ param.memberId }
>>${ requestScope.dto.memberId }
>>${ dto.memberId }
>>${ mep.memberId }
-- 내장객체
>> param
>> cookie
>> requestScope
>> sessionScope
>> applicaionScope
-- 연산자
>> 기호연산자 : < , > , ...
>> 키워드연산자 : empty, not, lt, gt, eq
JSTL
-- java 코드를 tag로 변환
-- 의존관계 라이브러리 가져오기 : jstl.jar
-- jsp 지시어 태그 지정:
<%@ taglib uri ="http://java.sun.com/jsp/jstl/core " prifix =" c"%>
-- 변수 선언
<c:set var="변수명 " value="값"/>
<c:if test="${ not empty memberId} ">
참인 경우 수행
</c:if>
-- 다중 조건:
<c:choose>
<c:when test="${조건식} ">
<c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
-- 반복 출력 : 배열, 콜랙션
<c: forEach var=" " items=" ">
${dto.memberId}
${dto.name}
</c:forEach>
-- 반복 출력: 카운팅(반복횟수 지정)
<c:forEach begin="1 " end=" 10" step="1">
</c:forEach>
에러처리방법
--error-code : 400(404- 요청페이지없는 경우, 401, ,403, 405)
--error-code : 500(서버오류)
1, web.xml
<error-page>
<error-code></error-code> | <exception-type></exception-type>
<location></loacation>
</error-page>
2, jsp
<%@page errorPage="url" %>
<%@ page isErrorPage="true" %> => 내장객체 exception 변환시에 제공
11. 서블릿 어노테이션
-- 서블릿 버전 2.x : web.xml
-- 서블릿 버전 3.x 지원
>> web.xml
>> @WebServlet Annotation
--서블릿 매핑
>> @WebServlet("/controller")
>>@WebServlet(value = "/controller")
>>@WebServlet(urlPatterns = "/controller")
>>@WebServlet(urlPatterns ={ "/controller", "/home", "/main"})
>>@WebServlet(urlPatterns ={ "/controller", "/home", "/main"}, loadOnStartup=1)
'Web' 카테고리의 다른 글
Front-End 개발 시작해보기 : Platform (0) | 2023.01.12 |
---|---|
[backend]월말평가대비 servlet API (0) | 2022.09.30 |
[WEB] 예외처리 (0) | 2022.09.22 |
[WEB]jsp경로설정 (0) | 2022.09.21 |
[WEB]JSP,EL,JSTL (0) | 2022.09.20 |