File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

Personalized URL with Struts

Tuan Le
Greenhorn

Joined: Nov 17, 2004
Posts: 4
Hi,

I want to give my client a personalized URL like http://www.mydomain.com/FirstNameLastName

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!
Tuan
Marc Peabody
pie sneak
Sheriff

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
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
You can access the URL information using the following methods in the javax.servlet.http.HttpServletRequest interface:
getContextPath()
getPathInfo()
getQueryString()
getRequestURL()
getRequestURI()
getServletPath()

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
Greenhorn

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

Tuan
Tuan Le
Greenhorn

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

REQUIREMENTS:
I want to give my client a personalized URL like http://www.mydomain.com/myWebApp/FirstName_LastName (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 (welcome.do) 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

http://www.mydomain.com/myWebApp/welcome.do?cid=FirstName_LastName

SOURCE:


Do you know what I'm missing?

Thanks,
Tuan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Personalized URL with Struts