Is it possible to map URLs to servlets (maybe something specific with Tomcat) so that the two following URLs (with {id}'s being variables retrievable from code),
/users/{id}/a
/users/{id}/b
map to two different servlets, or will I have to implement some sort of filter of my own for a servlet mapped to /users/*
?
To be more clear, any URL with the pattern /users/*/a
should map to the same servlet. The same goes for /users/*/b
.
This looks like it might be a good candidate for JAX-RS. I'm not sure what business logic your servlets currently perform, but this option addresses your servlet mapping question and may be appropriate.
@Path("/users/{id}")
public class User {
@Path("a")
public String doA(@PathParam("id") final int id) { ... }
@Path("b")
public String doB(@PathParam("id") final int id) { ... }
}
I don't think it's possible. Either use the UrlRewriteFilter
or some framework like Spring-MVC that is capable of mapping more complex URLs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With