Mathias Maes
Mathias Maes

Reputation: 501

How to create a multiple wildcard url pattern in web.xml?

How would one route the following path in Jetty ?

/users/user_id/transactions/transaction_id

I tried it this way:

/users/*/transactions/*

But I'm getting an error stating below :

java.lang.IllegalArgumentException: Servlet Spec 12.2 violation: glob '*' can only exist at end of prefix based matches: bad spec "/users/*/transactions"

What is the solution to this ?

Upvotes: 6

Views: 2430

Answers (1)

Anish B.
Anish B.

Reputation: 16469

In web.xml, if you give an URL pattern like this down below :

    <servlet-mapping>
       <servlet-name>servletName</servlet-name>
       <url-pattern>/users/*</url-pattern>
    </servlet-mapping>

So, the URL pattern /users/* denotes that all those requests will be accepted that starts with /users/ and ends with anything. For example : /users/get/all

But you can't give an URL pattern like /users/*/anything/*/.. which is not allowed.

A screenshot of 12.2 Specification of Mapping from Oracle - Java™ Servlet Specification Book - Version 4.0 :

enter image description here

Upvotes: 6

Related Questions