tags:

views:

153

answers:

2

Hi

If we have a person-directory application, where we can check the details of a specific person (for example, person with id 239) at

http://person-directory.com/detail.jsp?id=239

how can we create vanity urls in it? i.e. instead of typing the above url, we use

http://person-directory.com/julius

to open the detail page of person with id 239 and username julius.

Thanks

Umar

+6  A: 

I suspect you'll have to

  1. map a servlet to the root context (i.e. http://person-directory.com/)
  2. use the HttpServletRequest.getPathInfo() and extract the name from the URL your servlet has been called with
  3. use that name to do a lookup in your backend datasource

Note that a better URL may be http://person-directory/username/julius. Then you could map your UserServlet to http://person-directory/username and provide other servlets on other URLs.

Brian Agnew
This sounds like one way to do things. Before step 3, you could have a list of names to exclude as being part of the web site.
James P.
Yes. I think a better URL would be http://hostname/user/julius. I will amend the answer to include this
Brian Agnew
+1  A: 

You could also try to use the url-rewrite filter: http://tuckey.org/urlrewrite/. Of course, you have to change your code to query by username instead of id.

marcospereira