Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8668775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:17:54+00:00 2026-06-12T18:17:54+00:00

How do I filter requests with a specific parameter: e.g. filter only request with

  • 0

How do I filter requests with a specific parameter: e.g. filter only request with “csrf-token” parameter name. The filter will first check if the request has the required parameter name and bypass those without the required parameter.

Below is how I setup my web.xml file but the problem is that all requests are filtered:

<filter>
    <filter-name>CSRFTest</filter-name>
    <filter-class>org.example.CSRFFilter</filter-class>
    <init-param>
        <param-name>csrf_token</param-name>
        <param-value>csrf</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>CSRFTest</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>CrossSiteScriptStripper</filter-name>
    <filter-class>CrossSiteScriptStripperFilter</filter-class>
</filter>

<!-- Apply the CrossSiteScriptStripper filter to all servlets and JSP pages. -->
<filter-mapping>
    <filter-name>CrossSiteScriptStripper</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

The answers given by pb2q is working on my TEST PROJECT but I’m getting an error when inserted on my real project. I would like to ask if its possible to use 2 filters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:17:55+00:00Added an answer on June 12, 2026 at 6:17 pm

    Your Filter class will receive a ServletRequest in its doFilter method: this is analogous to a regular servlet’s service method (or doGet, doPost, for HTTPServlet).

    In your doFilter method, check the request for the required parameter using ServletRequest.getParameter: if the parameter doesn’t exist, the method will return null.

    If the parameter doesn’t exist then block the request: don’t pass it back into the filter chain using FilterChain.doFilter.

    Pseudocode:

    public void doFilter(ServletRequest req, ServletResponse resp,
                         FilterChain chain)
    {
        // ...
    
        if (req.getParameter(MY_PARAMNAME) != null)
            chain.doFilter(req, resp);
        // otherwise don't call doFilter
    
        // ...
    }
    

    I’m not sure what you’re expecting to do with the params in your config file, but if you want to specify which HTTP query parameter is required in the request, you might use this config/code combo:

    <param-name>required_parameter_name</param-name>
    <param-value>csrf-token</param-value>
    

    Then in your init method:

    public void init(FilterConfig filterConfig)
    {
        // ...
    
        // use this value in your doFilter method, in place of MY_PARAMNAME, above
        this.requiredParameterName =
            filterConfig.getInitParameter("required_parameter_name");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building an isapi filter that will grab any url requests with the prefix
I want to define a global before filter that will run before every request
I have an action filter that when used in certain specific conditions has to
I have setup a Filter for a specific set of requests i.e. */dispatch through
In the servlet 2.4 spec you can define dispatchers in the filter config [REQUEST
I have a Filter Servlet that filters request from a Servlet. I do not
I am trying to add filter functionality that sends a GET request to the
Given the following view : def comments(request): comments_list = Thing.objects.filter(thing_type=2) #Thing model extends MPTTModel
In my django views i have the following def create(request): query=header.objects.filter(id=a)[0] a=query.criteria_set.all() logging.debug(a.details) I
I'd like to know, inside a Filter doFilter method, whenever a request is for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.