이것은 해킹입니다. ServletConfig
은 기본적으로 Servlet
의 매개 변수를 포함하는 개체입니다. ServletRegistration
인터페이스에서 실제로 동일한 방법과 정보를 찾을 수 있습니다. 따라서 구성 매개 변수를 ServletContext
에서 꺼내고 ServletConfig
의 사용자 지정 구현으로 채우는 경우 모두 동일합니다. 이 시도 :
는 서블릿 컨텍스트부터 ServletContext
객체
FacesContext facesContext = FacesContext.getCurrentInstance();
ServletContext servletContext = (ServletContext) context.getExternalContext(); // Your servlet context here
검색, 당신은 당신에게
ServletRegistration reg = servletContext.getServletRegistration("theServlet"); //ServletRegistration contains all the info you'll need to populate a custom ServletConfig object
사용에게 정보를 원하는 서블릿 서블릿 등록 개체를 가져 ' (2)에서 파생 된 사용자 정의 impl을 채우기 위해 ServletConfig
ServletConfig myServletConfig = new MyCustomServletConfig();
myServletConfig.setInitParams(reg.getInitParameters()); //do a simple transfer of content
마지막 단계는 지나치게 단순화 된 것이지만 아이디어는 얻을 수 있습니다.
이전 버전의 Java EE (3.0 이전)를 실행 중이라면 ServletContext#getServlet()
에 대한 액세스 권한이 없어 졌으므로 더 이상 사용되지 않습니다.
@BalusC : 아, 요청을 처리하는 현재 Servlet 인스턴스를 얻는 방법이 필요하다고 생각했습니다. 나는'Servlet' 객체를 인스턴스화하고 그것이 어떻게되는지 보려고 할 것입니다. 감사! : D –
@BalusC : : P 현재 PrimeFace의 보안 문자를 사용하고 있습니다. 그러나, 내 응용 프로그램은 중국에서 사용되며 Captcha는 거기에 아주 잘 작동하지 않습니다. 따라서, 사장님은 저에게 대안을 찾아달라고 부탁하셨습니다. :) 나는 당신이 많은 captcha 솔루션으로 일했음에 틀림 없다고 생각합니다. D –
@ BalusC : 예, Servlet이 아닙니다. ServletConfig에 접근하기 만하면됩니다. 그래서'ServletConfig'에 접근 할 수 있도록 Managed bean 내부의'Servlet'에 접근하기를 원합니다. –