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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:56:47+00:00 2026-05-23T14:56:47+00:00

Case 1 <servlet-mapping> <servlet-name>myapp</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> Case 2 <servlet-mapping> <servlet-name>myapp</servlet-name> <url-pattern>*.do</url-pattern> </servlet-mapping> If I

  • 0

Case 1

  <servlet-mapping>
    <servlet-name>myapp</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

Case 2

  <servlet-mapping>
    <servlet-name>myapp</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>

If I use case 1 then I dont get any of my pages styled with <link rel="stylesheet" type="text/css" href="${contextPath}/assets/styles.css" />, but if I use case 2 everything gets styled.

Could someone help me understand why?

Also, could someone tell me which pattern should be used so that I don’t have to worry about extensions? Like should I be using /*? The thing is that if I use /* now when I’ve been using *.do while developing my application, everything seems to be breaking, not only the styles but I don’t get any pictures rendered, no JCaptcha and all that has to do with links.

And If I try to send a GET request from a REST Client like http://localhost:8080/myapp/user/1 it doesn’t work and I need to add .do at the end and send the same request like http://localhost:8080/myapp/user/1.do.

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-23T14:56:47+00:00Added an answer on May 23, 2026 at 2:56 pm

    Browsers sends separate HTTP requests on linked resources such as CSS files, JS files and images. The URLs of those requests also match the URL pattern of /. So your myapp servlet is also called on those requests. However, your myapp servlet doesn’t seem to process them properly, so those requests returns something entirely different. Try requesting those resources yourself separately to learn what your servlet is actually returning to the webbrowser:

    http://localhost:8080/myapp/assets/styles.css

    In your case, you want to let your myapp servlet ignore requests on those resources. The best way is to create a filter which does that. Assuming that all of those resources are in a folder called /assets, then you can achieve this by mapping your servlet on a more specific URL pattern, such as for example /myapp/* and creating a Filter listening on /* which transparently continues the request/response chain for any requests on /assets and dispatches all other requests to /myapp.

    So, this configuration

    <filter>
        <filter-name>filter</filter-name>
        <filter-class>com.example.Filter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <servlet>
        <servlet-name>controller</servlet-name>
        <servlet-class>com.example.Controller</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>controller</servlet-name>
        <url-pattern>/myapp/*</url-pattern>
    </servlet-mapping>
    

    in combination with the following in filter’s doFilter():

    String uri = ((HttpServletRequest) request).getRequestURI();
    if (uri.startsWith("/assets")) {
        chain.doFilter(request, response); // Goes to container's default servlet.
    } else {
        request.getRequestDispatcher("/myapp" + uri).forward(request, response);
    }
    

    should work for you.

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

Sidebar

Related Questions

I have a use case where a servlet (that has reasonably high concurrent use)
use case example I have a servlet that is receiving login requests. If a
Is there any handy way to use RESTEasy Asynchronous HTTP support (in my case
There's a case that the user change the parameters send to servlet through URL,
Im try to get my embedded jetty servlet to do some processing and then
Use case: A does something on his box and gots stuck. He asks B
Use case: 3rd party application wants to programatically monitor a text file being generated
For each servlet request I get, I pass, perhaps, 10 methods before I am
Here's a use case: I have a desktop application (built using Eclipse RCP) which
Since the Servlet 3.0 specification there is the possibility of declaring servlet mapping metadata

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.