In a content management system pages are often requested by using URL directory names (path) instead of using an unique parameter id, when getting content stored in a database, i.e:
Solution 1: URL request using directory name:
Solution 2: URL request using unique parameter id:
I am looking for an approach on how to use the directory name (path) as the unique id, like solution 1.
I am wondering about if there is any good practice on how to handle URL request using directory names? I guess we will need some main class or jsp page handling the request, getting the requested URI path and the getting the content related to the unique directory name '/about/thisDepartment/'.
Can anyone help me with some ideas? Do we use servlet listener, a 404 page, a basic RequestDispatcher to handle this?
I have some other questions regarding this approach:
I guess the front controller is a basic servlet. The front controller gets the path info from the http request, and use a RequestDispatcher object that forward to the jsp page using the path info as parameter?
If this is how it could be done, I guess we are using the path info as the unique id to get content from the database and not a unique record parameter like 'pid=233'
I also guess that the front controller is handling every single http request. How do we avoid it to run in an infinite loop if it´s called for each request, like?
Bear Bibeault wrote:Yeah, that's pretty much it. Except never map /* to anything!
Use a mapping like /xyz/* to address the front controller where 'xyz' is something that has meaning to your application.
Okay, but this way we always have to predefine the 'first path info name' in the web.xml, right?
Let´s say we have three main subjects in our website:
( I call the path /about/ = 'first path info name' )
Then we will need to predefine these three path info names in our web.xml like:
What if the these path info names are not predefined, but created by the webmaster from an user interface and he hasn´t access to the web.xml?
Okay, maybe I´m 'dull-witted' :-), but if I create a prefix called 'myPrefix', like:
- well then all links on the website has to point to this prefix, like:
- or am I wrong or how can we avoid this?