It's not a secret anymore!
The moose likes Struts and the fly likes Personalized URL with Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Personalized URL with Struts" Watch "Personalized URL with Struts" New topic

Personalized URL with Struts

Tuan Le

Joined: Nov 17, 2004
Posts: 4

I want to give my client a personalized URL like

Is there anyway I can capture the Firstname and the Lastname from the query string using Struts framework?

Because this URL does not have a filename e.g. .htm or .jsp and this does not hit my custom 404 as well.

Is this possible? I have seen some personalized e-cards like this.

One option is to create an HTML file for each customer (let's say we have 1000 customers) and inside HTML body have it redirect to a Struts action to process the customer information based on their unique first name and last name combination. But this option is not attractive for our case because of 2 reasons:

1) we have to generate 1000 HTML files with customer name
2) The URL has a file extension .html at the end.

Thanks in advance for your help!
Marc Peabody
pie sneak

Joined: Feb 05, 2003
Posts: 4727

Do the users have to log in when going to their page?

A good workman is known by his tools.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
You can access the URL information using the following methods in the javax.servlet.http.HttpServletRequest interface:

Just write a servlet that uses the above methods to access whatever information you want from the URL and map that to "/*" in your web.xml.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Tuan Le

Joined: Nov 17, 2004
Posts: 4
Thank you for your time and help!

Tuan Le

Joined: Nov 17, 2004
Posts: 4
Please help with my servlet mapping issue. It's calling my redirector class repeately and the redirector does not work.

I want to give my client a personalized URL like (NOTE: no file extension).

When the user enters that URL above, it would be processed by a servlet
RequestProfileRedirectorServlet, which is defined in web.xml and it has a servlet mapping to "/*" (NOTE: see servlet code and web.xml config below).

The main task for the RequestProfileRedirectorServlet is to get the request path info (NOTE: in my case it's /FirstName_LastName), build a redirect URL, and redirect it to a Struts welcome action ( to query the user profile from the database and display the user profile in a welcome view. An example of a redirect URL would be


Do you know what I'm missing?

It is sorta covered in the JavaRanch Style Guide.
subject: Personalized URL with Struts
It's not a secret anymore!