Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter not getting called

 
Aruneesh Salhotra
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • 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>
 
srinath anand
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic