0

I have a question on if this is possible to do. I have a profile servlet that has 2 url patterns, /profile and /profile/* .So in my project I have a user use GET /profile to get all of the profiles in JSON. Each profile has a favorite team string. Also, I use /profile/* for getting specific profiles by doing /profile/2 for example. Then I have profileFavTeam servlet that I want to get all of the data of the profile favorite team. So I need to get the profiles ID so I want the url to be /profile/"ID"/favteam and this would return the teams statistics.

So for example, If the profile ID is 2 has a favorite team called Liverpool, and I entered /profile/2/favteam, it would show the stats of Liverpool

So would my url for profileFavTeam in web.xml look like this because i want the user to put a number in ID /profile/*/favteam ?

But would this work if I have /profile/* url pattern in my profile servlet?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Bobby.lock
  • 59
  • 1
  • 7

1 Answers1

0

This would not work. You basically haven path mapping (ending with /*) or extension mapping (beginning with *.). See section 12.2 of the Servlet spec

In the Web application deployment descriptor, the following syntax is used to define mappings:

■ A string beginning with a ‘/’ character and ending with a ‘/*’ suffix is used for path mapping.

■ A string beginning with a ‘*.’ prefix is used as an extension mapping.

■ The empty string ("") is a special URL pattern that exactly maps to the application's context root, i.e., requests of the form http://host:port//. In this case the path info is ’/’ and the servlet path and context path is empty string (““).

■ A string containing only the ’/’ character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path and the path info is null.

■ All other strings are used for exact matches only.

If the effective web.xml (after merging information from fragments and annotations) contains any url-patterns that are mapped to multiple servlets then the deployment must fail.

You should implement the Front Controller pattern, with a single Servlet receiving all the requests, and delegate them to the processing objects according to the pattern.

areus
  • 2,880
  • 2
  • 7
  • 17