* include
-์ค๋ณต ๋์์ธ์ด๋ ์ฝ๋๋ฅผ ์ค์ผ ๋ชฉ์ ์ผ๋ก ์ฌ์ฉ.
-JSP๋ฅผ includeํ ์ ์๋ค.
<%@include %> //์ค๋ณต์ฝ๋๋ฅผ ์ฒ๋ฆฌํ ๋
<jsp:include/> //์ค๋ณต๋์์ธ์ ์ฒ๋ฆฌํ ๋(URI๋ง ๊ฐ๋ฅ)
<c:import /> //์ค๋ณต๋์์ธ์ ์ฒ๋ฆฌํ ๋(URI, URL ๋ชจ๋ ๊ฐ๋ฅ)
* jsp include
-webappํด๋ ํ์ jsp๊ฐ ์กด์ฌํ๋๊ฒฝ์ฐ.
<jsp:include page=“/๊ฒฝ๋ก/jsp๋ช ”/> //์ฒ๋ฆฌ๋ ๋ฐ์ดํฐ๋ฅผ ๋ณด์ฌ์ฃผ์ง ์๋ JSP
-WEB-INF/views ํด๋ jsp๊ฐ ์กด์ฌํ๋ ๊ฒฝ์ฐ.
<jsp:include page=“/WEB-INF/views/jsp๋ช ”/>
* do include
-์ก์ ํ๊ทธ, JSTL ๊ฐ๋ฅ. – ์ฝ๋์ ๋ณํฉ์ ์๋จ.<%@ include %>
<jsp:include file=“์์ฒญ.do”/>
<c:import url=“์์ฒญ.do”/>
- include๋๋ jsp์์๋ ์ธ๋ถ JSP์ ์์ฒญ๋ web parameter๋ฅผ ๋ฐ์ ์ ์๋ค.
* ๊ด๊ณ์ ์ง
- session, cookie
* session
-์ ์์ ๋ธ๋ผ์ฐ์ ์ id๋ฅผ ๋ถ์ฌํ๊ณ , ์ ์์์ ์ ๋ณด๋ฅผ ์๋ฒ์ธก ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅํ๋ ๊ธฐ์ .
-HttpServletRequest, HttpSession, @SessionAttributes๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
์ฌ์ฉ๋ฒ)
- HttpServletRequest ์ฌ์ฉ.
1. ์์ฒญ์ฒ๋ฆฌ method์ ๋งค๊ฐ๋ณ์๋ฅผ HttpServletRequest๋ก ์ ์ธํ๋ค.
public String method(HttpServletRequet request){
2. ์ธ์ ์ป๊ธฐ
HttpSession session=request.getSession();
- HttpSession์ฌ์ฉ
1.์์ฒญ์ฒ๋ฆฌ method์ ๋งค๊ฐ๋ณ์๋ฅผ HttpSession์ผ๋ก ์ ์ธํ๋ค.
public String method(HttpSession session){
-์ธ์ ๊ฐ ์ค์ : session.setAttribute(“์ด๋ฆ”,๊ฐ);
-์ธ์ ๊ฐ ์ป๊ธฐ : session.getAttribute(“์ด๋ฆ”);
-์ธ์ ์์กด์๊ฐ ์ค์ : DD์ค์ , session.setMaxInactiveInterval( ์ด );
-์ธ์ ๊ฐ ์ญ์ : session.removeAttribute(“์ด๋ฆ”);
-์ธ์ ๋ฌดํจํ : session.invalidate();
* @SessionAttributes
- class์์ ์ ์ธํ๋ค.
- Model์ ๊ฐ์ ์ด๋ฆ์ผ๋ก ๊ฐ์ ์ค์ ํ๋ฉด ์ธ์ ์ ๊ฐ์ด ํ ๋น ๋๋ค.
์ค์ - ์ฌ์ฉ๋ฒ)
1.SessionAttributes ์ ์ธ
@SessionAttributes({“์ด๋ฆ”,,,,})
@Controller
public class Test{
2. method์์ Model์ ๋งค๊ฐ๋ณ์๋ก ์ ์ธ.
public String method( Model model ){
3. SessionAttributes์ ์กด์ฌํ๋ ์ด๋ฆ๊ณผ ๋์ผํ ์ด๋ฆ์ผ๋ก ๊ฐ์ ์ค์ .
model.addAttribute(“์ด๋ฆ”,๊ฐ); //Model์ ๊ฐ์ ๋ฃ์๋๋ฐ request scope๊ณผ session scope์ ๊ฐ์ด ๋์์ ๋ค์ด๊ฐ๋ค.
-๊ฐ ์ป๊ธฐ) – Spring 5.2๋ถํฐ๋ Model.getAttribute method๊ฐ ์ถ๊ฐ๋์๋ค.
Controller ์ป๊ธฐ- HttpSession์ฌ์ฉ.
public String method( HttpSession session ){
session.getAttribute(“์ด๋ฆ”);
JSP์ป๊ธฐ
<% session.getAttribute(“์ด๋ฆ”) %>
${ sessionScope.์ด๋ฆ }
*์ธ์ ์ญ์
- org.sprginframework.web.bind.support.SessionStatus interface์ฌ์ฉ.
- HttpSession์ผ๋ก๋ ์ธ์ ์ญ์ ๊ฐ ๋์ง ์๋๋ค.
์ฌ์ฉ๋ฒ)
1. SessionStatus๋ฅผ ๋งค๊ฐ๋ณ์๋ก ์ ์ธ
public String method( SessionStatus ss){
2. ์ธ์ ๋ชจ๋ ๊ฐ ์ญ์
ss.setComplete();
*Cookie
- ๊ฐ์ ์ค์ ํ๋ ์ฝ๋๋ ์ด์ ์ ์ฝ๋๋ฅผ ๊ทธ๋๋ก ์ฌ์ฉ.
- @CookieValue๋ฅผ ์ฌ์ฉํ์ฌ ๊ฐ์ ์์ฝ๊ฒ ์ป์ ์ ์๋ค.
์ฌ์ฉ๋ฒ)
๊ฐ ์ค์ )
1. ์ฟ ํค๋ฅผ ์ฌ๊ธฐ์ํด HttpServletResponse๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค.
public String method( HttpServletResponse response){
2. ์ฟ ํค ์์ฑ.
Cookie cookie=new Cookie(“์ด๋ฆ”, “๊ฐ”);
3. ์์กด์๊ฐ ์ค์ . –์ค์ ํ์ง ์์ผ๋ฉด ๋ธ๋ผ์ฐ์ ๊ฐ ์ด๋ ค์๋ ๋์๋ง ์ ์ง
cookie.setMaxAge(์์กด์๊ฐ);
4. ์ฟ ํค์ฌ๊ธฐ
response.addCookie( cookie );
*์ฟ ํค ๊ฐ ์ป๊ธฐ
-๋งค๊ฐ๋ณ์๋ก ์ฟ ํค์ ์ค์ ๋ ๊ฐ์ ์ป๋๋ค.
@CookieValue(value=“์ฟ ํค์ด๋ฆ”,defaultValue=“์ฟ ํค๊ฐ ์์ ๋ ์ค์ ๋ ๊ฐ” )
public String method(@CookieValue()๋ฐ์ดํฐํ ๋ณ์๋ช , ,, ){
'๐ ๊ตญ๋น์ง์ํ์ > ๐Spring ์์ ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Spring] ํ์ 230517(์) (0) | 2023.07.15 |
---|---|
[Spring] ํ์ 230516(ํ) (0) | 2023.07.15 |
[Spring] ํ์ 230508(์) (0) | 2023.07.15 |
[Spring] ํ์ 230504(๋ชฉ) (0) | 2023.07.15 |