• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

code using the filter is not working

 
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic