This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.
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