• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Filter not getting called

 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The filter class is not getting called. I call the Servlet "VersionServlet". I expect the filter to also get invoked. Any ideas.

I have a filter class filterLog.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class filterLog implements Filter
{
private FilterConfig fc;

public void init(FilterConfig config) throws ServletException
{
this.fc = config;
}

public void doFilter (ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException
{
HttpServletRequest httpReq = (HttpServletRequest) req;
String name = httpReq.getRemoteUser();
if (name != null)
{
System.out.println("User " + name + " is updating");
}
chain.doFilter(req,resp);
}

public void destroy()
{
//
}
}

In my web.xml, I added the following lines.

<filter>
<filter-name>filterLog</filter-name>
<filter-class>filterLog</filter-class>
</filter>
<filter-mapping>
<filter-name>filterLog</filter-name>
<servlet-name>VersionServlet</servlet-name>
</filter-mapping>
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess your name is null that is why it is not even entering the if block.
 
Aruneesh Salhotra
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanx it works.

Also, is there is a functionality of filter that could monitor the response. I know it does.

But here it is what I need to check. If the servlet throws an exception, is it possible to still have the filter take the control.
reply
    Bookmark Topic Watch Topic
  • New Topic