• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

filter dispatcher doubt

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
You may have just won ten million dollars! Or, maybe a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic