Howto: Smart URLs
I had a problem, I’m not afraid to admit it. The URL’s on my site sucked. Example: http://cubanlinks.org/go/post.do?id=5
Obviously, this is a consequence of creating a dynamic site. There is one post template page, and it loads data from MySql based on an id. Unfortunately, to search engines and logfile analyzers, your site seems like it only has one page (post.do).
But, thanks to a couple servlets, that’s all behind me. Now, instead of URLs looking like this:
http://cubanlinks.org/go/post.do?section=home=tech
...to looking like this:
http://cubanlinks.org/go/section/home/tech/
For this example, I created a SectionServlet, mapped it to /section/*. The servlet parses its request.getPathInfo()
, which in this case would be /home/tech/, and forwards the request to the section Action (section.do) passing the appropriate parameters.
About Me
Hey there. My name is Carter Rabasa and I am a husband and father of two beautiful daughters Catherine and Emily. I live in Seattle, WA.
- @cubanlinks on Twitter