开发者

how to create vanity url in java web applications?

开发者 https://www.devze.com 2022-12-14 14:04 出处:网络
If we have a person-directory application, where we can check the details of a specific person (for example, person with id 239) at

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. inst开发者_如何学Pythonead 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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消