Ratna Dinakar has posted 2 posts at DZone. View Full User Profile

Simple Hack Alternative to URL Redirect for Struts Actions or Similar Frameworks

  • submit to reddit

Recently as a requirement I had to work on a URL Redirect for loading a particular Action as entry point.  As the usual procedure we choose one of the following methods to proceed with

  •  Pass the chosen url in sendRedirect method of HttpServletInterface
    * HttpServletResponse Object
  •  Pass the chosen url in HTML META tag and auto refresh page.
    <meta http-equiv="refresh" content="2;url=http://www.example.com/myapp/customAction.do">

Instead of using either of these, we can proceed and achieve this through the Web Application Deployment Descriptor ( web.xml)  file by following these steps.

  1. web.xml has tag elements <welcome-file-list> and <welcome-file> which route to default file(s) specified.
  2. Example of <welcome-file-list>
  3. To forward to a particular action file or similar.
  4. Create an empty file with the same name in  application war root folder [ Tested On JBoss 4.0.x and Tomcat Servers].
  5. After deployment, targeted ActionFile file can be accessed with default application URL, Instead of giving absolute URL.

As you can see above, we tested this on JBoss 4.0x and Tomcat. Please let me know whether we would need to create the empty files, as in Step 4, in other Java Application Servers.

Your rating: None
Published at DZone with permission of its author, Ratna Dinakar Tumuluri.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Chris Siemback replied on Fri, 2010/10/15 - 8:29am

Hmm, this only works if users are not specifying an actual resource. Also, this doesn't work if people use bookmarks to actual resources within the web app. This method is useful if you want to catch "most" of the incoming traffic - but if you have to redirect all traffic as a requirement - you'll need to apply different methods such as ServletFilters.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.