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

  • Home
  • SEARCH
  • 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 7697499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:01:43+00:00 2026-05-31T22:01:43+00:00

I am running Tomcat 5.5.4 and have a servlet running with no problems. However,

  • 0

I am running Tomcat 5.5.4 and have a servlet running with no problems. However, I’d like to set up a mapping to only launch the servlet when a URL containing a particular query string is submitted.

Right now in web.xml I have:
<servlet-mapping>
<servlet-name>MyServer</servlet-name>
<url-pattern>/go/*</url-pattern>
</servlet-mapping>

If a browser submits http://localhost/MyServer/go?P=123 the servlet is launched and all is well. However, I’d like to only launch that servlet if the URL is exactly as just shown. Unfortunately, right now if the URL is http://localhost/MyServer/go?P=AnyDarnThing the servlet still launches. I have tried setting up the following:
<url-pattern>/go?P=123</url-pattern>
but this results in The requested resource (/MyServer/go) is not available.

I’ve tried numerous variations (quoting the string, …) on the above URL pattern but I always get the above error. I notice that if I (for debugging purposes) drop the “?” as in
<url-pattern>/goP=123</url-pattern>
I no longer get the error message and the server launches (but, of course, it doesn’t respond to the “query string” because it’s not properly formed.) This suggest to me that the “?” is causing a problem in the mapping. I’ve tried replacing it with its URL special character equivalent as follows:
<url-pattern>/go%3FP=123</url-pattern>
but this gives the same result just described above when I tried dropping the “?” altogether.

I realize I can let the servlet get launched when any query string is submitted and then “ignore” the request for all but the one I care about but there is a reason I’d prefer to not have the servlet launched to begin with. So, my question is, how can I configure the servlet so that it is only launched when a specific query string is included?

Thank you.

  • 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-31T22:01:44+00:00Added an answer on May 31, 2026 at 10:01 pm

    You can’t do that using URL patterns.

    You can achive this using filters. Implement a filter which will forward to the Servlet only if the query params exists.

    Here is the how the filter will look like:

    public class ServletAcessFilter implements Filter
    {
      public void init(FilterConfig filterConfig) throws ServletException
      {
    
      }
    
      public void doFilter(ServletRequest request, ServletResponse response,
      FilterChain filterChain) throws IOException, ServletException
      {
        //validate the request, check if the request can be forwarded to servlet.
        if(request.getParameter("P").equalsIgnoreCase("123")){
            filterChain.doFilter(request, response);
        } else {
            //write what you want to do if the request has no access
            //below code will write 404 not found, you can do based on your requirement
            HttpServletResponse httpResponse = (HttpServletResponse) response;
            httpResponse.setStatus(404);
        }
      }
    
      public void destroy()
      {
    
      }
    }
    

    Define the filter in the web.xml like this:

    <filter>
        <filter-name>ServletAccessFilter</filter-name>
        <filter-class>com.ServletAcessFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>ServletAccessFilter</filter-name>
        <url-pattern>/go/*</url-pattern>
    </filter-mapping>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a servlet based webapp running on Tomcat 6 server. The URL scheme
I have a legacy Java servlet that is currently running in a Tomcat container.
I have Apache Tomcat Version 7.0.26 running. A have a JAX-RS servlet under /test,
I have a simple method (running on Tomcat 6.0.35) that looks like so: @RequestMapping(value
I have a simple servlet running in Tomcat. Because the servlet connects to a
I currently have a tomcat servlet 1 running under the ROOT: api1.myhost.com:8080/ I'm using
I have a Java servlet application running within Tomcat, there is one admin command
In tomcat 6 i have a servlet running openbluedragon, everything compiles and servers up
I currently have a tomcat container -- servlet running on it listening for requests.
I have created a JSP / servlets application running in Tomcat 7. It runs

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.