Description of Problem:

A typical Struts based web site might be configured to have requests
matching the pattern"*.do" sent to the ActionServlet.  After a request is
handled by its Action class, processing is typically forwarded to a .jsp
page.

However, it's also possible for users to directly request a .jsp page.
When this happens, the JSP container (in my case, Orion) will process the
.jsp page without any involvement by the ActionServlet.  Some .jsp pages
may yield unexpected results when called in this manner.


Examples:

  "Normal" Scenario
  1. client requests "edit.do"
  2. ActionServlet dispatches request to EditAction instance.
  3. EditAction forwards processing to "edit.jsp"
  4. client receives response handled by ActionServlet

  "Bad" Scenario
  1. client requests "edit.jsp"
  2. JSP container processes "edit.jsp" without using ActionServlet
  3. client receives response _not_ handled by ActionServlet


Quick and Dirty Workaround:

To insure that requests are handled by the ActionServlet, I subclassed the
ActionServlet and added code to set a request attribute named
"ActionServlet":

    private static final Boolean boolTrue = new Boolean(true);
    ...
    request.setAttribute("ActionServlet", boolTrue);

Then, near the top of each .jsp file, I inserted the following scriptlet,
which causes requests not processeded by the ActionServlet to be
redirected to a ".do" URL:

    <%
      if(request.getAttribute("ActionServlet") == null) {
        StringBuffer sb = new StringBuffer(request.getServletPath());
        sb.setLength(sb.length() - 3);
        sb.append("do");
        response.sendRedirect(sb.toString());
      }
    %>

(The above code should really be placed in a custom tag, but this serves
well enough for purposes of illustration.)


Questions:

1. Would it make sense to add a similar capability to Struts proper 
(modifying ActionServlet and adding a new custom tag), to provide a
standard mechanism for handling this situation?

2. Is there some better, yet portable way to handle this?

Joel


Reply via email to