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 680957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:25:48+00:00 2026-05-14T01:25:48+00:00

We have a situation where we want to use filter for URL’s containing some

  • 0

We have a situation where we want to use filter for URL’s containing some specific request parameters, e.g:

http://mydomain.com/?id=78&formtype=simple_form&.......    
http://mydomain.com/?id=788&formtype=special_form&.......    

and so on, id are fetched at run time, I want configure filter in web.xml only if formtype=special_form. How should achieve the solution? Can Filter be configured with regex patterns?

  • 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-05-14T01:25:49+00:00Added an answer on May 14, 2026 at 1:25 am

    As far as I know there is no solution for matching requests to filters by query string directly in web.xml. So you could register the filter in your web.xml using init-params to make the filter configurable and set a pattern via void init(FilterConfig filterConfig) in your javax.servlet.Filter implementation.

    package mypackage;
    
    import java.io.IOException;
    
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    
    public class MyFilter implements Filter {
    
        private String pattern;
    
        @Override
        public void destroy() {
            // TODO Auto-generated method stub
        }
    
        @Override
        public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
                throws IOException, ServletException {
            // check whether we have a httpServletRequest and a pattern
            if (this.pattern != null && request instanceof HttpServletRequest) {
                // resolve the query string from the httpServletRequest
                String queryString = ((HttpServletRequest) request).getQueryString();
                // check whether a query string exists and matches the given pattern
                if (queryString != null && queryString.matches(pattern)) {
                    // TODO do someting special
                }
            }
            chain.doFilter(request, response);
        }
    
        @Override
        public void init(FilterConfig filterConfig) throws ServletException {
            this.pattern = filterConfig.getInitParameter("pattern");
        }
    
    }
    

    The configuration would look like this in your web.xml:

    <!-- MyFilter -->
    <filter>
        <filter-name>myFilter</filter-name>
        <filter-class>mypackage.MyFilter</filter-class>
        <init-param>
            <param-name>pattern</param-name>
            <param-value>{{PATTERN HERE}}</param-value>
        </init-param>
    </filter>
    
    <filter-mapping>
        <filter-name>myFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    

    Further readings:
    http://java.sun.com/javaee/5/docs/api/javax/servlet/Filter.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a situation where I want to use several server side controls, which
I have a situation where I want to use the Meta options of unique_together
I am in a situation where I want to use mutable versions of things
I have a search page that allows the users to filter other users by
I have a situation I don't know how it's supposed to be solved. According
I am looking to develop some code that will be able to by looking
I have a question which I see from googling has been discussed at length..
I'm coding a report page. In this page, there are two date fields for
This was posted at Caliburn.Micro discussions also. I'm really looking for advice and opinions
Please consider this example: ( working example ) Style declarations: body {background:#333;font:1em Arial, Helvetica,

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.