Forwarding
์๋ธ๋ฆฟ ๋๋ JSP์์ ์์ฒญ์ ๋ฐ์ ํ์ ๋ค๋ฅธ component๋ก ์์ฒญ์ ์์ํ ์ ์๋ค. ๊ทธ๊ฒ์ ํฌ์๋ฉ์ด๋ผํ๋ค.
ํฌ์๋ฉ ๋ฐฉ๋ฒ์๋ 2๊ฐ์ ํด๋์ค(RequestDispatcher, HttpServletResponse)๋ฅผ ์ด์ฉํ๋ค.
RequestDispatcher ํด๋์ค

์์ฒญ๋ฐ์ ์์ฒญ๊ฐ์ฒด(request)๋ฅผ ์์๋ฐ๋ ์ปดํฌ๋ํธ(S2)์ ๋์ผํ๊ฒ ์ ๋ฌํ ์ ์๋ค.
์์
dispatcher.jsp
RequestObj.java
ํด๋ผ์ด์ธํธ๊ฐ ์ค request๊ฐ์ฒด์์ getRequestDispatcher("์์๋ฐ์ ์ปดํฌ๋ํธ") ๋ก ์์ฑํด์ค๋ค.
dispatcher.forward ๋ก ์ ๋ฌํด์ค๋ค. ๋ ํ์ผ์์ ์ฌ์ฉํ๋ ํ์ผ์ด ๋์ผํ request๋ผ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค.
HttpServletResponse ํด๋์ค
Request๋ฅผ ์์ํ๋ ํด๋์ค์ด๋ค. ํ์ง๋ง RequestDispatcher ํด๋์ค์์ ์ฐจ์ด์ ์ ์์ฒญ๋ฐ์ ๊ฐ์ฒด๋ฅผ ์์ ๋ฐ๋ ์ปดํฌ๋ํธ์ ์ ๋ฌํ๋ ๊ฒ์ด ์๋ ์๋ก์ด ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค.
์์
JSP
response.sendRedirect("RequestObj"); ๊ฐ HttpServletResponse ๊ฐ์ฒด์ด๋ค.
RequestObj.java
null๊ฐ์ด ๋จ๋ ๊ฒ์ ๋ณผ ์ ์๋ค. ์์์ ํ๋ค๊ณ ํด์ ๋ฐ๋ก ์ ๋ฌ๋๋ ๊ฒ์ด ์๋๋ผ ํด๋ผ์ด์ธํธ๊ฐ ๋ค์ ์์ ๋ฐ์ ์ปดํฌ๋ํธ๋ฅผ ์์ฒญํ๋ค. ์๋ก์ด ๊ฐ์ฒด๊ฐ ์์ฑ๋์ด ์ ๋ฌ๋๋ฏ๋ก ์์ฒญ๋ฐ์ ์ปดํฌ๋ํธ์ setAttribute ํด์ค ๊ฐ์ ์์๋ฐ์ Component๋ก ์ ๋ฌ๋์ง ์๋๋ค.
Last updated
Was this helpful?