내장 객체 9가지 <책 참조>
-8가지
-1가지
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1> Test2.jsp </h1>
<h2> 객체 Object </h2>
=> 내 눈 앞에 보이는 모든 대상
객체 추상화
객체 - 1) 속성 : 객체의 특징을 표현하기 위한 정보
=> 변수로 표현
2) 동작 : 해당 객체가 수행하는 모든 행동
=> 함수(메서드)로 표현
<h2> 내장 객체 (p177~) </h2>
=> JSP 페이지 -> 서블릿 클래스 필요한 정보(객체)를 미리 생성
<h3>javax.servlet 패키지</h3>
request : 클라이언트의 HTTP 요청 정보를 저장한 객체 <br>
response : HTTP 요청에 해당하는 응답정보를 저장한 객체<br>
session : 클라이언트의 세션정보를 저장한 객체 <br>
pageContext <br> : 페이지 실행에 필요한 컨텍스트 정보를 저장한 객체 <br>
out : 응답페이지를 전송하기위한 출력스트림 객체 <br>
application : 동일한 어플리케이션의 컨텍스트 정보를 저장한 객체 <br>
config : 페이지에 필요한 서블릿 설정 정보(초기화) <br>
page : 해당 페이지의 서블릿 객체<br>
<h3>java.lang 패키지 </h3>
exception : 예외를 처리하는 객체 <br>
</body>
</html>
Error 404
[404Err 페이지]
<body>
<h1>404Err.jsp</h1>
<img src =https://media.giphy.com/media/LpwXnLY924G4YszglQ/giphy.gif>
</body>
[Web.xml 페이지]
<error-page>
<error-code>404</error-code>
<location>/error/404Err.jsp</location>
</error-page>
Error 500
[500Err 페이지]
<body>
<h1>Err500.jsp</h1>
<iframe src="https://giphy.com/embed/3o6Zt6ML6BklcajjsA" width="480" height="360" frameBorder="0" class="giphy-embed" allowFullScreen></iframe><p><a href="https://giphy.com/gifs/cat-sleep-keyboard-3o6Zt6ML6BklcajjsA">via GIPHY</a></p>
</body>
[Web.xml 페이지]
<error-page>
<error-code>500</error-code>
<location>/error/Err500.jsp</location>
</error-page>
<템플릿 구조>
getParameter vs getAttribute
둘의 차이점은 리턴 타입
getParameter => String 타입을 리턴 받음
클라이언트의 HTML 페이지에서 필요한 정보를 얻는 데 사용함.
getAttribute => Object 타입을 리턴 받음 / 주로 빈 객체나 다른 클래스를 받아올 때 사용*attribute란 Servlet 간 공유하는 객체
getParameter()은 웹브라우저에서 전송받은 request 영역의 값을 읽어온다.getAttribute()의 경우 setAttribute() 속성을 통합 설정이 없으면 무조건 null 값을 리턴한다.
>>session으로 아이디 확인 할 때 빈 값이면 null 값이 뜸.
request.getParameter("num")은 웹브라우저에서 전송받은 request영역에서 name 값이 "num"인 것을 찾아 그 값을 읽어오는데 request.getAttribute("num")은 request.setAttribute("num","123")과 같이 setAttribute()를 통해 값을 설정해주지 않으면 null 값을 리턴받게 된다.
<TOP>
<body>
<h1>top.jsp</h1>
<h2>메뉴1 | 메뉴2 | 메뉴3 | 메뉴4 | 메뉴5 | 메뉴6</h2>
아이디 : <%=request.getParameter("id") %>
</body>
<bottom>
<body>
<h1>bottom.jsp</h1>
<h2>메뉴1 | 메뉴2 |</h2>
</body>
left 동일
<color>
<%
String col1 = "yellow";
String col2 = "pink";
String col3 = "red";
String col4 = "orange";
%>
<test1>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ include file="color.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body bgcolor="<%=col2%>">
<h1>Test1.jsp</h1>
<%=col1 %>
<h2> include 액션태그 (jsp:include)</h2>
=> 각 각의 페이지를 컴파일 한 후 페이지를 추가(jsp)
<h2>include 지시어 (@ include)</h2>
=> 코드를 병합해서 컴파일 수행
<table border="1" width = "800" height = "1000">
<tr>
<td colspan="2" height = "200">
<!-- <h1> TOP2</h1> -->
<!-- top.jsp?id=ITWILL -->
<jsp:include page="top.jsp">
<jsp:param value="ITWIlL" name="id"/>
</jsp:include>
</td>
</tr>
<tr>
<td width = "200">
<!-- <h1>LEFT</h1> -->
<jsp:include page="left.jsp"></jsp:include>
</td>
<td>
<h1>MAIN</h1>
</td>
</tr>
<tr>
<td colspan="2" height = "200">
<!-- <h1>Bottom</h1> -->
<jsp:include page="bottom.jsp"></jsp:include>
</td>
</tr>
</table>
</body>
</html>
<scopeForm>
<body>
<h1>scopeForm.jsp</h1>
<h2> 영역(scope) : 내장객체 중에서 데이터를 공유하는 객체의 범위 </h2>
<h2> 속성(attribute) : 영역에서 공유되는 데이터 </h2>
<h3> 영역 </h3>
page < request < session < application <br>
<h3> 영역 객체 </h3>
pageContext < request < session < application <br>
</body>
* page-pageContext : 해당 페이지가 클라이언트에게 서비스를 제공할때만 사용 (이 페이지 실행될때만 데이터를 공유할 수 있다?)
* request-request : 클라이언트의 요청이 처리되는 상황에만 사용
* session-session : 세션이 유지되는 동안에만 사용(브라우저당 1개의 영역)
* application-application : 웹 애플리케이션이 실행되는 동안 사용
영역의 범위가 밑으로 갈 수록 커짐
<ScopeForm> - 실행시키는 파일
<hr>
<form action = "scopePro.jsp" method = "get">
아이디 : <input type = "text" name "id"><br>
<input type = "submit" value = "전송">
</form>
<scopePro>
<h1>scopePRo.jsp</h1>
<%
//영역객체 정보 저장
request.setAttribute("id", "BUSAN");
pageContext.setAttribute("p", "pageValue");
request.setAttribute("r","requestValue");
session.setAttribute("s","sessionValue");
application.setAttribute("a","applicationValue");
%>
<%
String id = request.getParameter("id");
%>
<h3>아이디 : <%= id %></h3>
<%
//영역 객체 정보 가져오기
String id2 = (String)request.getAttribute("id");
%>
<h3>아이디 : <%=id2 %></h3>
<hr>
page : <%= pageContext.getAttribute("p") %>
request : <%=request.getAttribute("r") %>
session : <%=session.getAttribute("s") %>
application : <%=application.getAttribute("a") %>
'Spring > Model1 _2(MVC)' 카테고리의 다른 글
0818 JSP - cookieForm => cookiePro ~ session (0) | 2022.08.18 |
---|---|
[JSP] 8/9 (0) | 2022.08.09 |
[JSP] 8/9 (0) | 2022.08.09 |
[JSP] 8/2 (0) | 2022.08.02 |
[8/1] JSP (0) | 2022.08.01 |