Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Servlet Mappings with Variables(Tomcat 7.0)

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.

like image 921
irwinb Avatar asked Nov 24 '11 05:11

irwinb


2 Answers

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) { ... }

}
like image 109
shelley Avatar answered Oct 02 '22 22:10

shelley


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

like image 33
Bozho Avatar answered Oct 02 '22 21:10

Bozho