This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes code using the filter is not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "code using the filter is not working" Watch "code using the filter is not working" New topic
Author

code using the filter is not working

Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
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.


Anil Deshpande
SCJP 1.5, SCWCD 1.5
Hasnain Javed Khan
Ranch Hand

Joined: Nov 23, 2007
Posts: 73
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

Joined: Jan 13, 2008
Posts: 119
It is not printing null to me inside doFilter(). I am using apache tomcat 5.5.27
Anil Deshpande
Ranch Hand

Joined: Jan 13, 2008
Posts: 119
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
Chinmaya Chowdary
Ranch Hand

Joined: Apr 21, 2008
Posts: 432
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: code using the filter is not working
 
Similar Threads
Facing Issue in implementing Listeners and Filters
Q: Filter on Page 668 and page 695
web app with filter is not getting deployed
fiter help needed
FilterChain.doFilter(), what if I don't call this in Filter.doFilter()'s impl?