๋‚Œ๋‚Œ
ggim
๋‚Œ๋‚Œ
์ „์ฒด ๋ฐฉ๋ฌธ์ž
์˜ค๋Š˜
์–ด์ œ
  • โ—พโ—ฝ (96)
    • ๐Ÿ’ฌPL (8)
      • ๐Ÿ’ซJava (8)
    • ๐Ÿ’พDB(Database) (2)
      • โญ•Oracle (1)
    • ๐Ÿ ๊ตญ๋น„์ง€์›ํ•™์› (76)
      • ๐Ÿ“–Java ์ˆ˜์—… (28)
      • ๐Ÿ“–DB ์ˆ˜์—… (14)
      • ๐Ÿ“–HTML ์ˆ˜์—… (5)
      • ๐Ÿ“–CSS ์ˆ˜์—… (3)
      • ๐Ÿ“–JavaScript ์ˆ˜์—… (8)
      • ๐Ÿ“–JSP ์ˆ˜์—… (13)
      • ๐Ÿ“–Spring ์ˆ˜์—… (5)
    • ๐Ÿ’ป๊ฐœ์ธ ๊ณต๋ถ€ (1)
      • ์ž๋ฐ”์˜ ์ •์„ (1)
    • ๐Ÿ’ผ (8)
      • โœ…๊ธฐ๋ณธ ์„ค์น˜ (6)
      • ๐ŸงLinux (2)
    • ๐Ÿ”ฅ๋‹ค์ง (1)

๋ธ”๋กœ๊ทธ ๋ฉ”๋‰ด

  • Home
  • ํƒœ๊ทธ
  • ๋ฐฉ๋ช…๋ก

ํ‹ฐ์Šคํ† ๋ฆฌ

hELLO ยท Designed By ์ •์ƒ์šฐ.
๋‚Œ๋‚Œ

ggim

[Spring] ํ•™์› 230510(์ˆ˜)
๐Ÿ ๊ตญ๋น„์ง€์›ํ•™์›/๐Ÿ“–Spring ์ˆ˜์—…

[Spring] ํ•™์› 230510(์ˆ˜)

2023. 7. 15. 14:20

 * 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
    '๐Ÿ ๊ตญ๋น„์ง€์›ํ•™์›/๐Ÿ“–Spring ์ˆ˜์—…' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€
    • [Spring] ํ•™์› 230517(์ˆ˜)
    • [Spring] ํ•™์› 230516(ํ™”)
    • [Spring] ํ•™์› 230508(์›”)
    • [Spring] ํ•™์› 230504(๋ชฉ)
    ๋‚Œ๋‚Œ
    ๋‚Œ๋‚Œ
    zzZ zzZ zzZzz

    ํ‹ฐ์Šคํ† ๋ฆฌํˆด๋ฐ”