Interceptor(์ธํฐ์
ํฐ)
ํน์ URI ๋ก ์์ฒญ์ Controller ๋ก ๊ฐ๋ ์์ฒญ์ ๊ฐ๋ก์ฑ๋ ์ญํ .
์ธํฐ์
ํฐ๋ฅผ ์ง์ํ๋ ์ธํฐํ์ด์ค์ ์ถ์ ํด๋์ค
- HandlerInterceptor
- HandlerInterceptorAdapter
HandlerInterceptorAdapter ์ 3๊ฐ์ง ๋ฉ์๋
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
: Controller ๋ก ์์ฒญ์ด ๋ค์ด๊ฐ๊ธฐ ์ ์ํ
postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView)
: ์ปจํธ๋กค๋ฌ์ ๋ฉ์๋์ ์ฒ๋ฆฌ๊ฐ ๋๋๊ณ return ํ ํ๋ฉด์ ๋์์ฃผ๋ ์ฒ๋ฆฌ๊ฐ ๋๊ธฐ ์ง์ ์ ์ด ๋ฉ์๋๊ฐ ์ํ๋จ.
afterCompletion()
: ์ปจํธ๋กค๋ฌ๊ฐ ์ํ๋๊ณ ํ๋ฉด ์ฒ๋ฆฌ๊น์ง ๋๋ ๋ค ํธ์ถ.
์ฌ์ฉ๋ฐฉ๋ฒ | Interceptor(์ธํฐ์
ํฐ) ๊ตฌ์ฑ
๋ก๊ทธ์ธ ์ฌ๋ถ๋ฅผ ํ์ธํ๋ ์ธํฐ์
ํฐ ํด๋์ค ๊ตฌ์ฑ.
์๋ ์ฝ๋๋ ๋ก๊ทธ์ธ ๊ธฐ๋ฅ ๊ตฌํ ์ค ์ปจํธ๋กค๋ฌ๋ก ์ด๋ํ๊ธฐ ์ ์ธ์
๊ฒ์ฆ์ ์ํด ์ธ์
์ ๋ฌด์ ์กฐ๊ฑด์ ์ค์ ํ๋ค.
์ฌ์ฉ๋ฐฉ๋ฒ | Spring ์ค์ ๋ฑ๋ก
dispatcher-servlet.xml ์ด๋ servlet-context.xml ์์ ์ธํฐ์
ํฐ ๋น(bean) ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ , ์ธํฐ์
ํฐ ์ ๋ณด๋ฅผ ๋ฑ๋กํ๋ค.
ํด๋น ๊ฐ์ฒด์ ์ด๋ค url์ด ์์ฒญ์์ ์ธํฐ์
ํฐ๊ฐ ์๋ํ ์ง๋ฅผ ์ค์ ํ๋ค.
๋ก๊ทธ์ธ ยท ์์ ์ฒ๋ฆฌ
๋ก๊ทธ์์์ ํ์์๋ ๋ค๋ก๊ฐ๊ธฐ ์ ๋ก๊ทธ์ธ ์ํ๋ก ๋จ์์๋ ๊ฒ์ด ๋ฌธ์ .
์ด๋ฐ ํ์์ ์์ธ์ ๋ธ๋ผ์ฐ์ ์บ์์ ์๋ ๊ฐ์ ๋ค์ ์ฝ๊ธฐ ๋๋ฌธ์ ์ด๋ฐ ์ผ์ด ๋ฐ์ํ๋ ๊ฒ.
์ฝ๋๋ฅผ ์ถ๊ฐํด ๋ค๋ก๊ฐ๊ธฐ ์ ์บ์๊ฐ ๋จ์์์ง ์๋๋ก ํ๋ค.
ํด๋น ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๊ธฐ ์ํด์ dispatcher-servlet.xml ์ด๋ servlet-context.xml ํ์ผ์์ ์ฝ๋๋ฅผ ์ถ๊ฐํด์ค๋ค.
์ถ์ฒ | ์
๋๊ณ ์ฉ์ฃผ์ ๊ฐ๋ฐ ์ผ๊ธฐ