2 Replies Latest reply: Feb 18, 2011 10:08 AM by _blackjack RSS

    Is it possible to pass/receive params from url hiding the servlet/action ?

    _blackjack
      Hi All,

      I was wondering if it's possible to collect a single parameters through url without showing the servlet's name. What i mean is something like facebook does for mapping users names to their profiles. For instance, www.facebook.com/my_name.
      Is it possible to receive that parameter without make an explicit call to either servlet or action ?
      Thanks a lot
        • 1. Re: Is it possible to pass/receive params from url hiding the servlet/action ?
          gimbal2
          It is not a parameter. Parameters comes after the question mark. It is actually part of the url. Without knowing details, most likely facebook works on a REST interface (Google that).


          A really simple trick to do it with a basic servlet is to map a servlet to a specific pattern, such as /profiles/*. Then when you type in the url somewebsite.com/profiles/harry or somewebsite.com/profiles/bill, the single servlet will be invoked for both urls. In your servlet you can then investigate the url to see which name was added to the back of the url.

          Another trick (I'd venture towards a hack really) to use is to not configure a specific servlet but use the error handling built into the system. If the url cannot be found a 404 will be generated, for which you can configure an error handler in the web.xml to redirect to and from there do the trick of investigating the url to get the name.
          • 2. Re: Is it possible to pass/receive params from url hiding the servlet/action ?
            _blackjack
            I think that's a pretty good way to go.
            Thanks a lot !