I was trying using servlet filtering when an strange (for me) behaviour occurred. I applied the filter on a servlet, namely secondservlet. In my tests I re-used the code on the slides to buil the dispatcher servlet, namely firstservlet: its task is to forward the request received to secondservlet. Thus, it call secondservlet. Now, if I call secondservlet directly from browser the filter intercept the request (how I expect it to be). Instead, if I call secondservlet indirectly (namely calling firstservlet) the filter will be skipped. Is this behaviour correct or is a bug of java? The documentation of filter say that they was created to facilitate re-usability of code, but in the case I was precedently using a dispatcher? I must eliminate all of them and substitute them with filters? Where's the problem? Ps: The code in enclosure is realized with JBuilder and to use it, launch the tomcat server and call from browser http://localhost:8080/MyApp/firstservlet o http://localhost:8080/MyApp/secondservlet
|