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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:11:29+00:00 2026-05-18T21:11:29+00:00

I hope someone can point out where I’m going wrong here. I’m trying to

  • 0

I hope someone can point out where I’m going wrong here. I’m trying to create a simple filter that works something like Paul Tuckey’s URLRewriteFilter, but stripped down to do only what I need it to do.

I can’t get it to stop looping back on the original URI. I’ve snooped around the URLRewriteFilter code and it seems to be doing basically the same thing I’m doing. Here’s my filter code:

public static final String dispatcherURI = "/Dispatcher?q=";
public void doFilter(final ServletRequest request, final ServletResponse response,
                     final FilterChain chain)
        throws IOException, ServletException {
    final HttpServletRequest rq = (HttpServletRequest)request;
    final HttpServletResponseWrapper rsw =
        new HttpServletResponseWrapper((HttpServletResponse)response);
    final String uri = rq.getRequestURI();
    if (uriIsDispatchable(uri)) {
        final String forwardPath = dispatcherURI+uri;
        rq.getRequestDispatcher(forwardPath).forward(rq, rsw);
        LOG.info("Forward From: "+uri+", To: "+forwardPath);
    }
    else {
        try { chain.doFilter(request, response); }
        catch (Exception e) {
            LOG.error(e);
            throw new RuntimeException(e);
        }
    }
}

// checks URI against an ArrayList of URIs that should be ignored.
private static boolean uriIsDispatchable (final String uri) {
    boolean result = true;
    for (String i : ApplicationValues.uriIgnore) {
        if (uri.indexOf(i) == 0) {
            result = false;
            break;
        }
    }
    return result;
}

Here’s the filter entry in web.xml

<filter>
    <filter-name>UrlRewriteFilter</filter-name>
    <filter-class>myapp.filter.URLRewrite</filter-class>
</filter>
<filter-mapping>
    <filter-name>UrlRewriteFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

Some notes on the code:
A URI like /home should be forwarded to a dispatcher servlet like so: /Dispatcher?q=/home
the dispatcher servlet then determines what code to execute based on what’s in the query string.

The filter correctly ignores the URIs in the “uriIgnore” ArrayList (including /Dispatcher), but the forward keeps looping on /home. For completeness sake, here’s the contents of the uriIgnore ArrayList which is searched in the uriIsDispatchable method above:

public static final List<String> uriIgnore = new ArrayList<String>(4);
static {
  uriIgnore.add("/Dispatcher");
  uriIgnore.add("/netbeans-tomcat-status-test");
  uriIgnore.add("/resources");
  uriIgnore.add("/robots.txt");
}

Also, I’m running the latest Tomcat 6 proxied behind Apache.

Any help is appreciated. Thanks.

  • 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-18T21:11:30+00:00Added an answer on May 18, 2026 at 9:11 pm

    I’ll get around to figuring this out when I have time to peruse the URLRewrite Filter code further, but in the meantime it seems that if I really want the highest performance URL rewriting, I’ll just let mod_rewrite and Apache do it.

    My solution (I’m sure there’s a better way to do this also):

    # .htaccess file contents
    # Apache has the same docroot as the Java web app.
    # Java webapp is running on port 8084
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f [NC,OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    # directory where images, static html files and JS scripts are located.
    # Apache will serve these.
    RewriteRule ^resources - [L,NC]
    # obviously, we want Apache to serve robots.txt
    RewriteRule ^robots.txt$ - [L,NC]
    RewriteRule ^(.*)$ http://localhost:8084/Dispatcher?q=$1 [L,P,QSA]
    </IfModule>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm staring blank on this error, so I hope someone here can point out
This really, really urks me, so I hope that someone can give me a
Really hope someone can point me in the right direction as I have no
I hope someone can guide me as I'm stuck... I need to write an
I'm very confused about the whole user profile thing in drupal, hope someone can
Cocoa's NSScrollView is horribly under-explained. I hope someone here knows what it's all about
I hope someone could help me on this. I want to add a month
The docs at www.fastcgi.com aren't clear on this (to me), so I hope someone
Hope anyone can shed light on this so I can use pens with dash
I'm trying to learn a little bit more about recursion but somehow I can't

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.