aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes filter dispatcher doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "filter dispatcher doubt" Watch "filter dispatcher doubt" New topic
Author

filter dispatcher doubt

Raju Sri
Ranch Hand

Joined: Mar 10, 2004
Posts: 108
Hi ranchers,

In which case MyFilter in the below web.xml configuration will trigger ?

<filter-mapping>
<filter-name>MyFilter</filter-name>
<servlet-name>HelloServlet</servlet-name>
<dispatcher>ERROR</dispatcher>
</filter-mapping>

I tested dispatcher with REQUEST,INCLUDE and FORWARD by calling HelloSevlet from diffent servlet using requestDispatcher.They are working fine.

I tried to test dispatcher with ERROR in the web.xml and couldn't able to test. I configured web.xml with error-page and changed my HelloServlet to throw Exception but the MyFilter never triggered when there is an error.

Pls let me know how to test ?

Regards


SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3<br />SCDJWS 1.4
V Sharma
Greenhorn

Joined: Jun 26, 2004
Posts: 26
I tried to test dispatcher with ERROR in the web.xml and couldn't able to test. I configured web.xml with error-page and changed my HelloServlet to throw Exception but the MyFilter never triggered when there is an error.



I think HelloServlet should be catching the exception. The called to the filter will be made in case Servlet is invoked by means of error thrown mechanism from some other servlet.

<filter>
<filter-name>HelloWorldFilter</filter-name>
<filter-class>com.TestHelloWorldFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HelloWorldFilter</filter-name>
<servlet-name>HelloWorldServ</servlet-name>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>
<filter-mapping>
<filter-name>HelloWorldFilter</filter-name>
<servlet-name>TestErrorDispServ</servlet-name>
<dispatcher>ERROR</dispatcher>
</filter-mapping>

<error-page>
<exception-type>java.lang.ClassCastException</exception-type>
<location>/servlet/TestErrorDispServ</location>
</error-page>

Hope this helps.
Raju Sri
Ranch Hand

Joined: Mar 10, 2004
Posts: 108
Hi Victor,

I used the web.xml like below and it is working fine.I tested this with another servlet which throws IOException. Thanks for your help.
##############################################################
<filter-mapping>
<filter-name>MyFilter</filter-name>
<servlet-name>HelloServlet</servlet-name>
<dispatcher>ERROR</dispatcher>
</filter-mapping>

<error-page>
<exception-type>java.lang.IOException</exception-type>
<location>/HelloServlet</location>
</error-page>
##############################################################

Cheers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: filter dispatcher doubt