2014-01-07 4 views
0

에서 error.jsp를 throw하는 방법 필터에서 리소스로 전달할 때 우리는 RequestDispatcher 또는 FilterChain> doFilter 메서드를 사용하고 있습니다. 그리고 FilterChain doFilter를 내 코드에서 사용했습니다. 왜냐하면 리소스로 전달되기 때문에 (필터가 설명자에서 찾을 수없는 경우) 그렇지 않으면 필터입니다.리소스로 사용자 정의 Exception을 필터

try catch 블록 내에서이 FilterChain doFilter 호출을 래핑하고 필터는 ServletException 또는 IOException 만 throw합니다. ServletException을 throw하는 대신 필터에서 사용자 정의 Exception (내 액션 클래스에서 throw 된)을 throw 할 수 있습니까? 내가 뭐라도 잘못하고있어.

답변

0

이 시도 .... 저를 알려 주시기 바랍니다 :

여기
public void doFilter(ServletRequest request, 
       ServletResponse response, 
       FilterChain chain) 
       throws java.io.IOException, ServletException,WIUException { 


     String ipAddress = request.getRemoteAddr(); 

     if(ipAddress != null){ 
      throw new WIUException("It is an WIU Exception"); 
     } 
     chain.doFilter(request,response); 
    }

WIUException 사용자 정의 Exception.This가 도움이 확인할 수이다.

+1

이미이 종류의 사용자 지정 예외가 있지만 필터는 서블릿 예외를 throw하기 때문에 필터에서이 예외를 throw 할 수 없습니다. – raky

+0

시나리오에 대한 내 대답이 바뀌 었습니다 –

+0

chain.doFilter는 리소스 또는 필터로 전달합니다. 리소스로 전달 된 경우 리소스가 예외를 throw하면 예외가 발생합니다 ... right? – raky