페이징
1,2,3,4,5[다음 블럭][마지막 페이지]
[이전 블럭][처음페이지],6,7,8,9,10[다음 블럭][마지막 페이지]
<a href="http://localhost:8090/el_chap05/boardlist.jsp?pageNum=1">6</a>
한 페이지당 출력할 게시글 수 10개
한 화면에 페이지 번호 개수 5개
1) 전체 페이지 수
전체 게시글 / 10
Math.ceil(전체게시글/10)
55/10 ---> 5.5 ---> 6
52/10 ---> 5.2 ---> 6
2) 각 페이지마다 출력할 게시물의 범위
1페이지 1~10
2페이지 11~20
범위의 시작값 1,11,21,31,41,... -> (현재 페이지 -1) * 10 + 1
범위의 마지막값 10,20,30,40,... -> 현재 페이지 * 10
3) 블럭
1~5페이지까지 1
6~10페이지까지 6
11~15페이지까지 11
블럭변수가 1일 때는 이전페이지 블럭 바로가기가 나타나지 않고
6일때부터 나타남
이전페이지 블럭 바로가기에 블럭변수-1
각 페이지 번호를 출력
블럭변수가 1일 때 <a href='주소?'></a> 1,2,3,4,5
블럭변수가 6일 때 6,7,8,9,10
utils패키지 생성 -> BoardPage 생성 -> 정적메소드 호출 -> 문자열을 리턴
pageStr = "";
블럭번호 1이 아닐 때
<a href=">[처음페이지]</a>
<a href=">[이전블럭]</a>
1,2,3,4,5
el (Expression Language)
표현 언어
변수의 값을 출력할 때 사용하는 스크립트 언어
4가지 영역에 접근하거나 사용자의 요청을 처리하기 위한
내장객체를 제공함
1. 4가지 영역에 접근하기 위한 내장객체
- pageScope
pageContext 내장객체와 같이 page영역에 저장된 속성값을 읽음
- requestScope
request 내장객체와 같이 request영역에 저장된 속성값을 읽음
- sessionScope
session 내장객체와 같이 session영역에 저장된 속성값을 읽음
- applicationScope
application 내장객체와 같이 application영역에 저장된 속성값을 읽음
스코프 객체
사용하기 전
<%
String name = (String) request.getAttribute("name");
String id = request.getParameter("userId");
%>
<%=name%>
<%=id%>
사용 후
${requestScope.name}
${param.userId}
// getParameter() 받지않고 바로 출력 가능
2. 폼값 처리하기
request.getParameter()로 폼에 입력값을 받을 수 있음
param과 paramValues를 사용
1) param : request.getParameter("매개변수명")
2) paramValues : request.getParameterValues("매개변수명")
매개변수의 값을 문자열 배열로 받음
3. 객체 전달하기
4. 쿠키, http헤더, 컨텍스트 초기화 매개변수 출력하기
<context-param>
<param-name>username</param-name>
<param-value>green</param-value>
</context-param>
cookie : 쿠키를 읽을 때 사용
header : request.getHeader()와 동일하게 헤더값을 읽을 때 사용
pageContext : jsp의 pageContext내장 객체와 동일한 역할을 함
initParam : web.xml에 설정한 컨텍스트 초기화 매개변수를 읽을 때 사용
el패키지 생성
MyElClass 만들기
복습 230704
1. el 내장객체
<%
pageContext.setAttribute("scopeValue", "페이지")
request.setAttribute("scopeValue", "리퀘스트")
session.setAttribute("scopeValue", "세션")
application.setAttribute("scopeValue", "어플리케이션")
%>
pagaScope, requestScope, sessionScope, applicationScope
${영역지정, 속성명}
or
${속성명}
2. 폼값 처리
param
paramValues
<%
String userName = request.getParameter("userName")
%>
<%= userName%>
------------------------------------
위의 식을 아래처럼 param으로 줄여서 사용 가능
${param.userName}
<%
String checkbox1 = request.getParameter("checkbox1")
%>
<input type="checkbox" name="checkbox1" value="a">
<input type="checkbox" name="checkbox1" value="b">
<input type="checkbox" name="checkbox1" value="c">
-------------------------------------
위의 식처럼 value만 다른 다중선택가능 checkbox를 아래처럼
param 배열로 사용 가능
${paramValues.checkbox1[0]}
3. 객체 속성
<%
request.setAttribute("personObj", new Person("김그린", 32))
%>
${personObj.age}
4. 쿠키, http헤더, 컨택스트 초기화 매개변수 읽기
<%
Cookie cookie = new Cookie("username", "green");
response.addCookie(cookie);
%>
${header.host} ${header["host"]} ${header['host']}
${cookie.username.value}
${header['user-agent']}
${header.cookie}
${initParam.userId}
${pageContext.request.contextPath} -> 컨택스트 루트 경로 읽기
5. 컬렉션 요소 출력
<%
List<String> sList = new ArrayList<String>();
sList.add("a");
sList.add("b");
sList.add("c");
pageContext.setAttribute("greenlist", sList)
%>
${greenlist[2]}
6. 메소드 호출
<%
MyClass myclass = new MyClass();
pageContext.setAttribute("a", myclass)
%>
${a.helloprint()}
${MyClass.isNumber("123")}