• Post Reply Bookmark Topic Watch Topic
  • New Topic

code using the filter is not working  RSS feed

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have written a small code to check how filters work. I will just give you the description of the code

The Filter code:BeerRequestFilter.java


The servlet code: TestingServlet.java



Thwn the web.xml file



Now the url that I am giving in the web browser is : http://localhost:8080/testfilter/test.do

this is not executing anything inside the filter System.out.println() statements

What changes I have make.
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

this is not executing anything inside the filter System.out.println() statements



Its working fine with me. I can see the output

This is filter Initialization

when the server deploys the web application.

I also added the following line



in doFilter method which is getting called as well and printed out " null ".

Can you post the version of the server you are using ?

kind regards.
Hasnain.
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not printing null to me inside doFilter(). I am using apache tomcat 5.5.27
 
Anil Deshpande
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just went through the code. it was not printing the null because it was returning null. If I placed that statement outside if statement in printed me the null value. So this is perfectly working example. Thanks for the reply though
 
Ranch Hand
Posts: 437
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anil.

Now the url that I am giving in the web browser is : http://localhost:8080/testfilter/test.do

this is not executing anything inside the filter System.out.println() statements



In BeerRequestFilter.java, the method getRemoteUser() returns 'null', if the user is not authenticated. See HttpServletRequest's getRemoterUser() method. Because of this, System.out.println("Just printed the username "+name); is not executed in the following code part.



The System.out.println("This is filter Initialization") in
will be executed during container startup, during initialization phase.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!