You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by bu...@apache.org on 2002/04/18 19:33:36 UTC

DO NOT REPLY [Bug 8271] New: - multiple servlet-mappings to action servlet don't work as expected

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8271>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=8271

multiple servlet-mappings to action servlet don't work as expected

           Summary: multiple servlet-mappings to action servlet don't work
                    as expected
           Product: Struts
           Version: 1.1 Beta 1
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Documentation
        AssignedTo: struts-dev@jakarta.apache.org
        ReportedBy: tiaxajeff@hotmail.com


The documentation needs to make it VERY clear, probably somewhere in the 
section discussing path mapping (/do/) vs extension mapping (*.do), that the 
use of more than one servlet-mapping to the Struts Action servlet is not 
supported and will either fail outright or work unreliably.

Examples of things not allowed:

<!-- can't map more than one path to Struts
in an attempt to convey additional information
or parameters to the mapped action via the URL itself -->
<servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>/do_in_english/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>/do_in_spanish/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>/do_in_portuguese/*</url-pattern>
</servlet-mapping>


<!-- can't have both path and extension mapped to Struts -->
<servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>/do/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
  <servlet-name>action</servlet-name>
  <url-pattern>*.do</url-pattern>
</servlet-mapping>

attempting to map multiple paths, or simultaneously use path AND extension 
mapping via multiple servlet-mappings in web.xml is not allowed and will not 
work consistently, even though Tomcat will happily accept it and launch the 
Action servlet. Specifically, the behavior of the html:form tag will cause it 
to either generate insidious errors (sending form data to an unintended 
mapping) or fail outright (if the unintended mapping doesn't match a defined 
action-mapping in struts-config.xml)

Concrete example:
I recently attempted to create a multi-lingual web app that used paths to 
convey language (mainly, because the original app I wrote did it that way, and 
I wanted to migrate the old apps to the Struts universe a little at a time 
without breaking URLs on other pages pointing to them).

in web.xml, I created three servlet-mappings for Struts' Action servlet:
/admin/en/*
/admin/es/*
/admin/pt/*

in struts-config.xml, the actions themselves were mapped, including:
/item/view
/item/edit

the net result was that calls to http://localhost/admin/en/item/view and 
http://localhost/admin/es/item/view were properly mapped to the Struts Action 
servlet and didn't generate errors because Struts was able to recognize and 
map /item/view to an action, but the html:form tag on the jsp output template 
used by it whose "action" attribute was "/item/edit" inevitably rendered into a 
<form> tag whose "action" attribute was "/admin/pt/item/edit".

The expected behavior, of course, was that Struts would prepend the servlet-
mapping that launched it ("/admin/en" or "/admin/es") to the action specified 
by the html:form tag. The actual apparent behavior was for the last-defined 
servlet-mapping to be used.

In addition, the documentation needs to stress that Struts does NOT support the 
simultaneous ad-hoc use of BOTH path and extension-mapping (say, while 
migrating from one to the other). In other words, users can NOT create servlet-
mappings to BOTH "/do/" and "*.do" in an effort to migrate from one system to 
the other a little bit at a time. If the user tries, a html:form tag whose 
action="/some_action" on a jsp template launched in response to a call 
to "http://host/do/some_action" (as well as in struts-config.xml) might 
generate a html form tag whose "action" attribute is "/do/some_action.do", 
which will generate a runtime error since /do/some_action.do is not defined in 
struts-config.xml.

As much as I'd dearly love to make html:form into a scapegoat and recommend 
that it be enhanced to simply implement the expected behavior detailed above, I 
don't know enough about the architecture underlying Struts to know whether this 
is merely an oversight/shortcut bug with the html:form tag, and patching the 
html:form tag would make everything work, or whether it would simply uncover 
another architectural issue elsewhere.

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>