I added some static HTML pages to my Appfuse 1.9.4 (Struts/Hibernate)
application today. Right away, I got 404 errors when trying to access
those pages. After some research, I identified the cause of the issue as
the .html servlet mapping for the struts action servlet. This is well
documented in previous mailing list discussions. The use of Michael
Horwitz's DojoFilter is the recommended solution to address this issue.

 

I plugged the DojoFilter into my Struts app and had success loading the
static pages, but my forms no longer worked. It seems that the
DojoFilter was only verified to be working with Spring MVC and the
solution causes some trouble with Struts 1.2.

 

The problem is that use of the DojoFilter requires the removal of the
*.html servlet-mapping in your web.xml. The Struts ActionServlet reads
and stores the servlet-mapping element to determe what extension to add
to action URLs. It is then used by the html:form tag in JSPs to build
appropriate values for a form tag's action attribute. If removed, from
the web.xml, the action URLs are not built correctly.

 

I was able to work around this issue by extending the Struts
ActionServlet class and adding code to setup the servletMapping variable
if it doesn't have a value after normal initialization. I am posting
here in case others might find the solution useful.

 

//// MY ACTION SERVLET CODE

 

package org.appfuse.webapp.action;

 

import javax.servlet.ServletException;

 

/**

 * Extension of struts action servlet that allows configuration of the
internal

 * servletMapping variable. This variable is required for correct
functioning of 

 * the html:form tag as it drives the extension that is added to the end
of

 * action URLs. This is useful when no servlet-mapping element is
present

 * in the web.xml for the action servlet. One such case is the use of
the DojoFilter

 * to serve both static and dynamic .html pages. With DojoFilter, no
servlet-mapping

 * is specified for the ActionServlet.

 * 

 * @author Corey Sanders

 */

public class ActionServlet

       extends org.apache.struts.action.ActionServlet

{

       public static final String DEFAULT_SERVLET_MAPPING = "*.html";

       

       protected void initServlet() throws ServletException 

       {

              super.initServlet();

              

              if( this.servletMapping == null )

              {

                     String configuredMapping =
getServletConfig().getInitParameter("servletMapping");

                     if( configuredMapping != null )

                     {

                           servletMapping = configuredMapping;

                     } else

                     {

                           this.servletMapping =
DEFAULT_SERVLET_MAPPING;

                     }

              }

       }

} 

 

//// MY SERVLET CONFIGURATION (web.xml)

 

<servlet>

  <servlet-name>action</servlet-name>

 
<servlet-class>com.sterlingcommerce.bpn.webapp.action.ActionServlet</ser
vlet-class>

  <load-on-startup>2</load-on-startup>

  <init-param>

    <param-name>servletMapping</param-name>

    <param-value>*.html</param-value>

  </init-param>

</servlet>

 

 

References

 

http://www.nabble.com/Re%3A-Changing-default-extension-from-*.html-to-*.
---p8745725s2369.html

http://issues.appfuse.org/secure/attachment/10257/DojoFilter.java

 

 

---

Corey Sanders

Senior Software Developer

Sterling Commerce, an AT&T Company

Phone: (614) 659-6860

Fax: (614) 793-7045

 

Reply via email to