I have a music blog, where people can write their own article or review as a blog entry and it would show up among other blog entries.
Each blog entry should have a URL associated with it, similar to:
www.myblog.com/blog/title-of-blog-entry
How would I achieve this using Struts2 ? Can I dynamically add an entry in the struts.xml file or use wildcard mapping in the xml file, or something like that?
The best shot is to use the Advanced Wildcard Mapppings (there are other wildcard usages, and also the Struts2 Rest Plugin as commented by @AleksandrM, but the closest to your needs is AWM).
You can read the details in this answer and in the two answers linked by it, other than in the official documentation (also linked).
That said, consider that an URL exactly like the one you've posted is missing an artificial key, and is using the name of the article as key. You must be ready to handle duplicate titles, handle special characters conversion and preservation, and so on.
It would be easier (also if less elegant) to have a key like StackOverflow URLs.
Take as example my profile:
https://stackoverflow.com/users/1654265/andrea-ligios
you could change it to
https://stackoverflow.com/users/1654265/chuck-norris
and it still would open my profile. The key is 1654265
, the descriptive part is completely ignored by StackOverflow, but is important because it allows you to search by name in the browser address bar and history (exactly like the page's title)
You can't remember the URL nor the date you've opened a page, but after you've opened the page once, if you remember a single word that was in its URL, you can go in the Address Bar of your browser and enter it to retrieve the page immediately (eg. entering "Ligios" you can retrieve the page).
A final obbservation: you're not forced to have the blog
part too in the URL if you mount your application in the root context. Then you could have:
www.myblog.com/title-of-blog-entry
or
www.myblog.com/123456/title-of-blog-entry
if using an artificial key.