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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:49:02+00:00 2026-06-01T05:49:02+00:00

I have a Filter Servlet that filters request from a Servlet. I do not

  • 0

I have a Filter Servlet that filters request from a Servlet. I do not want to do something on a request for a Image, so I have for example this code:

if (baseURL.endsWith("png")) 
{
 chain.doFilter(servletrequest, servletresponse);
}

Which on the doFilter method of of the filter, I don’t do anything and just call chain.doFilter, I expected that the response image will be sent properly in the client however the Content-Type that comes back is "application/octet-stream" instead of "image/png"

Any idea why this happens?

  • 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-01T05:49:04+00:00Added an answer on June 1, 2026 at 5:49 am

    I have a Filter Servlet that filters request from a Servlet. I do not want to do something on a request for a Image

    The FilterChain#doFilter() does not prevent that the request ends up in your servlet if its URL pattern also matches the request URL. You seem to be thinking that this is the case. This is thus not correct.

    If you do not want that image requests end up in your servlet, then you have to map the servlet on a more specific URL pattern. For example, /app/* instead of /*. Then you can filter the requests as follows:

    if (httpServletRequest.getRequestURI().endsWith(".png")) {
        chain.doFilter(request, response);
    }
    else {
        request.getRequestDispatcher("/app" + httpServletRequest.getRequestURI()).forward(request, response);
    }
    

    The URL pattern of /* should not be used on servlets, but on filters only.

    Further, the content type is by default already automatically determined based on the file extension. I assume that you really have a some.png resource, not a somepng resource as your initial endsWith() argument value would also match.

    See also:

    • How to access static resources when mapping a global front controller servlet on /*
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does cgi scripts have something like servlet filters. I.e. a piece of code that
I have a servlet filter in my Java app to ensure that users are
I have a servlet Filter that acts as the basis of my web stack.
I have a servlet filter that adds a random amount of latency to each
I have a filter that takes an incoming request, and then wraps it with
I have to filter a text file filter.tmp containing two types of lines, this
I have a filter: class MyFilters { def filters = { before = {
I have to filter out certain elements from an array in javascript and thought
i'm studying Pixel Bender. i have a filter who's parameter i want to tween.
I have an ISAPI filter that I am using to do URL rewriting 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.