[Spring] redirect | forward

Jeiniยท2023๋…„ 5์›” 24์ผ
0

๐Ÿƒย  Spring

๋ชฉ๋ก ๋ณด๊ธฐ
10/33
post-thumbnail

๐Ÿ’ก RedirectView๊ฐ€ redirect ์ฒ˜๋ฆฌ


โœ”๏ธ ์‘๋‹ต ํ—ค๋”๋ฅผ ๋งŒ๋“ค์–ด ๋ƒ„

  • Controller์—์„œ ๋ฐ˜ํ™˜๊ฐ’์œผ๋กœ redirect ๋ฌธ์ž์—ด ํฌํ•จ โžก๏ธ RedirectView์—๊ฒŒ ์ „๋‹ฌ

  • RedirectView ๋Š” ์‘๋‹ต์„ ๋งŒ๋“ค์–ด๋‚ด๊ณ  Client๋Š” ์ด ์‘๋‹ต์„ ๋ฐ›์•„์„œ ์‘๋‹ต ์ƒํƒœ์ฝ”๋“œ๊ฐ€ 302๋‹ˆ๊นŒ location์— ์žˆ๋Š” URL๋กœ ์žฌ์š”์ฒญ์„ ํ•ด์•ผ๋˜๊ฒ ๊ตฌ๋‚˜ํ•˜๊ณ  ๋ธŒ๋ผ์šฐ์ €๊ฐ€ ์ž๋™์œผ๋กœ ์š”์ฒญ์„ ๋ณด๋‚ด์ค€๋‹ค.

๐Ÿ’ก JstIView


โœ”๏ธ JSP๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” View

  • Spring์—๋Š” ๋‹ค์–‘ํ•œ View๋“ค์ด ์žˆ๋‹ค.
  • ์šฐ๋ฆฌ๊ฐ€ JSP๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์œผ๋‹ˆ๊นŒ JstIView ๋ฅผ ์“ฐ๋Š” ๊ฒƒ

๐Ÿ’ก InternalResourceView๊ฐ€ forward ์ฒ˜๋ฆฌ


โœ”๏ธ ๋‚ด๋ถ€์ ์œผ๋กœ ์š”์ฒญ forwarding

  1. โ€œregister/addโ€๋กœ ํฌ์›Œ๋”ฉํ•˜๋ผ๊ณ  ์ปจํŠธ๋กค๋Ÿฌ ๋ฉ”์„œ๋“œ๊ฐ€ ์ € ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•˜๋ฉด, DS๊ฐ€ ๋ฐ˜ํ™˜๋œ ๋ฌธ์ž์—ด์„ ๋ฐ›์•„์„œ forward๋กœ ์‹œ์ž‘ํ•˜๋‹ˆ๊นŒ ํฌ์›Œ๋”ฉํ•ด์•ผ ํ•˜๋Š”๊ตฌ๋‚˜ ์ธ์‹์„ ํ•˜๊ณ  ๋ฌธ์ž์—ด์„ InternalResourceViewํ•œํ…Œ ์ „๋‹ฌํ•œ๋‹ค.

  2. ๊ทธ๋Ÿผ InternalResourceView ๊ฐ€ register/add ๋ฅผ ํ˜ธ์ถœํ•˜๊ณ  DSํ•œํ…Œ ์•Œ๋ ค์ค€๋‹ค. (๋‚ด๋ถ€์ ์œผ๋กœ ์š”์ฒญ forwarding)

  1. ๊ทธ๋Ÿผ DS๊ฐ€ register/add ์—ฐ๊ฒฐ๋œ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•œ๋‹ค.
  2. View ์ด๋ฆ„์„ ๋ฐ˜ํ™˜๋ฐ›๋Š”๋‹ค. (registerForm)
  3. IRVRํ•œํ…Œ ์‹ค์ œ View ์ด๋ฆ„์„ ๋ฐ›๋Š”๋‹ค.
  4. ๋ฐ›์€ ๊ฑธ JstlView์—๊ฒŒ ์ค€๋‹ค.
  5. registerForm.jsp๋ฅผ ํ˜ธ์ถœํ•ด์„œ ์ด jsp๊ฐ€ ์‘๋‹ตํ•œ๋‹ค.

Reference
: https://fastcampus.co.kr/dev_academy_nks

profile
Fill in my own colorful colors๐ŸŽจ

0๊ฐœ์˜ ๋Œ“๊ธ€