File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Problem in simple Filter servlet Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem in simple Filter servlet Program" Watch "Problem in simple Filter servlet Program" New topic
Author

Problem in simple Filter servlet Program

Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
Hi all ,
I'm new to Servlets .I just studied filtering in Servlets and tried a small program .

Here is the coding



Here is the part of web.xml content for this filter



The problem is Filtering is not working .
I find that doFilter method is not invoked at all when I request "FilterDemo" servlet (which is suppose to be invoked ).
Please tell me what is the problem in that coding .

Thanks in advance
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Why are your classes not in packages? That's the first thing to take care of in order to eliminate that as a possible source of error.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

yes,as beer mentioned above

-------------------------------
<filter-class>FilterLifeCycle</filter-class>
-------------------------------

this should be fully qualified class name.
Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
Hi thanks for your replies .
I tried after put it in to package but still (as previous) filter's init() and destroy() methods alone invoked .
Is anything I'm missing in filter mapping ?
I'm using tomcat 5.5.x series
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

Originally posted by seetharaman venkatasamy:
yes,as beer mentioned above


The name is Bear, serious typo I must say


SCJP, SCWCD.
|Asking Good Questions|
Amit Ghorpade
Bartender

Joined: Jun 06, 2007
Posts: 2718
    
    6

I tried after put it in to package but still (as previous) filter's init() and destroy() methods alone invoked .


Why do you think that the doFilter() was not called? What is your output in the browser?
Wasn't the servlet (or the next filter in the chain) invoked?
Parthiban Malayandi
Ranch Hand

Joined: Apr 15, 2008
Posts: 70
Hi all,

After struggling for a day I found out the problem .

The problem is due to "Invoker" Servlet.While practicing small programs normally I take advance of using "Invoker" servlet without explicitly providing servlet mapping for each servlet in web.xml that is the problem.

If I do so doFilter method is not invoked where as the requested servlet works perfectly but if I explicitly provide url-pattern for that servlet(or url-pattern for that filter) doFilter method of that Filter is invoked

Thanks to all for your replies
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61761
    
  67

Lesson learned: take no shortcuts even for smaller programs.

But yeah, if you map the filter to a servlet mapping, and then don't use that mapping, no filter will be invoked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in simple Filter servlet Program