dwr 에서 request, session 사용하기 / WebContextFactory is deprecated
dwr 에서 request, session 사용하기 / WebContextFactory is deprecated
dwr 을 사용중에 request 와 session 을 사용할 일이 생겼다.
session 은 reqeust 가 있으면 getSession() 으로 사용할 수 있기 때문에 request 를 구하는 방법에 대해 알아본다.
request 는 WebContextFactory.get() 함수로 호출할 수 있다고 한다.
dwr java 함부 내부에서 다음과 같이 호출한다.
1
2 |
WebContext wctx = WebContextFactory.get();
HttpServletRequest request = wctx.getHttpServletRequest(); |
cs |
이제 WebContext, WebContextFactory 클래스를 import 해주면 된다.
그런데 두 클래스 모두 import할때 보면 패키지는 다르지만 클래스명이 동일한 클래스가 2개 있다.
패키지를 살펴보면 다음과 같이 2개로 구분할 수 있다.
uk.ltd.getahead.dwr org.directwebremoting |
검색해보니 대략적으로
uk.ltd.getahead.dwr 패키지는 1.x 대 버전인것 같고
org.directwebremoting 패키지는 2.x 대 버전인거 같다.
1.x 대 버전의 uk.ltd.getahead.dwr 패키지 아래에 있는 클래스를 import 하면
The type WebContextFactory is deprecated |
라고 나온다.
그렇기 때문에 다음과 같이 2.x 대 버전의 패키지에 있는 클래스를 import 한다.
1
2 |
import org.directwebremoting.WebContext;
import org.directwebremoting.WebContextFactory; |
cs |
Tip
WebContextFactory 에서 한번에 HttpServletRequest 를 호출할 수도 있다.
1 |
HttpServletRequest request = WebContextFactory.get().getHttpServletRequest(); |
cs |