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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:31:01+00:00 2026-06-14T19:31:01+00:00

I have a servlet which acts as a front controller. @WebServlet(/*) However, this also

  • 0

I have a servlet which acts as a front controller.

@WebServlet("/*")

However, this also handles CSS and image files. How can I prevent this?

  • 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-14T19:31:03+00:00Added an answer on June 14, 2026 at 7:31 pm

    You have 2 options:

    1. Use a more specific URL pattern such as /app/* or *.do and then let all your page requests match this URL pattern. See also Design Patterns web based applications

    2. The same as 1, but you want to hide the servlet mapping from the request URL; you should then put all static resources in a common folder such as /static or /resources and create a filter which checks if the request URL doesn’t match it and then forward to the servlet. Here’s an example which assumes that your controller servlet is a @WebServlet("/app/*") and that the filter is a @WebFilter("/*") and that all your static resources are in /resources folder.

      HttpServletRequest req = (HttpServletRequest) request;
      String path = req.getRequestURI().substring(req.getContextPath().length());
      
      if (path.startsWith("/resources/")) {
          chain.doFilter(request, response); // Goes to default servlet.
      } else {
          request.getRequestDispatcher("/app" + path).forward(request, response); // Goes to your controller.
      }
      

      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

I have a Java Servlet, which is handling a REST request. However, this is
I have this servlet which needs to send mail using Java Mail API, however
I have a servlet which is used to display image.This servlet actually called by
I have a servlet which takes us to an existing jsp, say home.jsp. This
I have a servlet class which handles login. At the end of my login
I have a servlet which serves an image file which was stored in a
I have a java servlet which accepts an image a user uploads to my
I have a servlet which handles http get requests that I'd like to be
I have a servlet in which I want to output normal text and also
So I have a servlet which prints content of various files. But when I

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.