-2

I am trying to create a simple application using Java and Servlets.

In my app, there are users, and each one should have his/her own page.

I think the URLs for this page should look like:

www.myapp.com/users/john
www.myapp.com/users/paul
...

and so on.

In Django, there are ways to capture parts of the URL. For example, for what I would like to do above, you would create a URL entry like url(r'^articles/([a-z])/$', views.userpage)

How do you do this with Java servlets, web.xml, etc?

CodyBugstein
  • 21,984
  • 61
  • 207
  • 363

1 Answers1

1
@Path("/users/{username}")
public class UserResource {

    @GET
    @Produces("text/xml")
    public String getUser(@PathParam("username") String userName) {
        ...
    }
}

Documentation: http://docs.oracle.com/javaee/6/tutorial/doc/gilik.html

Really nice tutorial: http://www.vogella.com/tutorials/REST/article.html

Bruno Franco
  • 2,028
  • 11
  • 20