Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

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

DZone's Guide to

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

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

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
    */
    response.sendRedirect("/customAction.do");
  •  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>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
  3. To forward to a particular action file or similar.
    <welcome-file>customAction.do</welcome-file>
  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.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.

Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}