Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

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.
 
Get me the mayor's office! I need to tell him about this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic