craigmcc 01/03/13 14:31:57
Modified: src/conf struts-config_1_0.dtd
src/share/org/apache/struts/action ActionMapping.java
ActionResources.properties ActionServlet.java
web/example/WEB-INF struts-config.xml
Log:
Add a "delegate via RequestDispatcher.forward()" capability, analogous to
the "delegate via include" capability added yesterday. This allows
working around the following limitations of RequestDispatcher.include():
- Included resources cannot set response headers or cookies
- Request path information for included resources is passed in request
attributes, so the resource needs to know it is being included
rather than called directly.
Revision Changes Path
1.14 +11 -5 jakarta-struts/src/conf/struts-config_1_0.dtd
Index: struts-config_1_0.dtd
===================================================================
RCS file: /home/cvs/jakarta-struts/src/conf/struts-config_1_0.dtd,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- struts-config_1_0.dtd 2001/03/11 02:50:07 1.13
+++ struts-config_1_0.dtd 2001/03/13 22:31:44 1.14
@@ -11,7 +11,7 @@
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
- $Id: struts-config_1_0.dtd,v 1.13 2001/03/11 02:50:07 craigmcc Exp $
+ $Id: struts-config_1_0.dtd,v 1.14 2001/03/13 22:31:44 craigmcc Exp $
-->
@@ -265,10 +265,15 @@
configured as the "mapping" initialization parameter
to the Struts controller servlet.
+ forward Context-relative path of the servlet or JSP resource that
+ will process this request, instead of instantiating and
+ calling the Action class specified by "type". Exactly one
+ of "forward", "include", or "type" must be specified.
+
include Context-relative path of the servlet or JSP resource that
will process this request, instead of instantiating and
calling the Action class specified by "type". Exactly one
- of "include" and "type" must be specified.
+ of "forward", "include", or "type" must be specified.
input Context-relative path of the input form to which control
should be returned if a validation error is encountered.
@@ -298,9 +303,9 @@
type Fully qualified Java class name of the Action class
(implements org.apache.struts.action.Action) to be
- used to process requests for this mapping if the "include"
- attribute is not included. Exactly one of "include" and
- "type" must be specified.
+ used to process requests for this mapping if the "forward"
+ or "include" attribute is not included. Exactly one
+ of "forward", "include", or "type" must be specified.
unknown Set to "true" if this action should be configured as the
default for this application, to handle all requests
@@ -315,6 +320,7 @@
<!ATTLIST action id ID #IMPLIED>
<!ATTLIST action attribute %BeanName; #IMPLIED>
<!ATTLIST action className %ClassName; #IMPLIED>
+<!ATTLIST action forward %RequestPath; #IMPLIED>
<!ATTLIST action include %RequestPath; #IMPLIED>
<!ATTLIST action input %RequestPath; #IMPLIED>
<!ATTLIST action name %BeanName; #IMPLIED>
1.16 +46 -9
jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java
Index: ActionMapping.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- ActionMapping.java 2001/03/11 02:50:09 1.15
+++ ActionMapping.java 2001/03/13 22:31:48 1.16
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java,v 1.15
2001/03/11 02:50:09 craigmcc Exp $
- * $Revision: 1.15 $
- * $Date: 2001/03/11 02:50:09 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java,v 1.16
2001/03/13 22:31:48 craigmcc Exp $
+ * $Revision: 1.16 $
+ * $Date: 2001/03/13 22:31:48 $
*
* ====================================================================
*
@@ -106,14 +106,20 @@
* names when populating the properties of our <code>ActionForm</code>
* bean (if any). <em>DEPRECATED - use <code>suffix</code>
* instead</em>.
+ * <li><strong>forward</strong> - Context-relative path of the resource that
+ * should serve this request (via a call to
+ * <code>RequestDispatcher.forward()</code>) instead of instantiating the
+ * Action class specified by the <code>type</code> property.
+ * Exactly one of the <code>forward</code>, <code>include</code>, or
+ * <code>type</code> properties must be specified.
* <li><strong>forwards</strong> - The set of ActionForwards locally
* associated with this mapping.
* <li><strong>include</strong> - Context-relative path of the resource that
* should serve this request (via a call to
* <code>RequestDispatcher.include()</code>) instead of instantiating the
- * specified Action class specified by the <code>type</code> property.
- * Exactly one of the <code>include</code> and <code>type</code> properties
- * must be specified.</li>
+ * Action class specified by the <code>type</code> property.
+ * Exactly one of the <code>forward</code>, <code>include</code>, or
+ * <code>type</code> properties must be specified.</li>
* <li><strong>input</strong> - Context-relative path of the input form
* to which control should be returned if a validation error is
* encountered. Replaces the old <code>inputForm</code> property.
@@ -140,8 +146,8 @@
* <li><strong>type</strong> - Fully qualified Java class name of the
* <code>Action</code> implementation class used by this mapping.
* Replaces the old <code>actionClass</code> property. Exactly one of
- * the <code>include</code> and <code>type</code> properties must be
- * specified.</li>
+ * the <code>forward</code>, <code>include</code>, or <code>type</code>
+ * properties must be specified.
* <li><strong>unknown</strong> - Set to <code>true</code> if this action
* should be configured as the default for this application, to handle
* all requests not handled by another action. Only one action can be
@@ -152,7 +158,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.15 $ $Date: 2001/03/11 02:50:09 $
+ * @version $Revision: 1.16 $ $Date: 2001/03/13 22:31:48 $
*/
public class ActionMapping implements Serializable {
@@ -169,6 +175,15 @@
/**
+ * The context relative path of the servlet or JSP resource (to be called
+ * via <code>RequestDispatcher.forward()</code>) that will process this
+ * request, rather than instantiating and calling the Action class that is
+ * specified by the <code>type</code> attribute.
+ */
+ protected String forward = null;
+
+
+ /**
* The set of ActionForward objects associated with this mapping.
*/
protected ActionForwards forwards = new ActionForwards();
@@ -440,6 +455,28 @@
public void setFormSuffix(String formSuffix) {
setSuffix(formSuffix);
+
+ }
+
+
+ /**
+ * Return the forward path for this mapping.
+ */
+ public String getForward() {
+
+ return (this.forward);
+
+ }
+
+
+ /**
+ * Set the forward path for this mapping.
+ *
+ * @param forward The forward path for this mapping
+ */
+ public void setForward(String forward) {
+
+ this.forward = forward;
}
1.8 +1 -1
jakarta-struts/src/share/org/apache/struts/action/ActionResources.properties
Index: ActionResources.properties
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionResources.properties,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- ActionResources.properties 2001/03/11 02:50:10 1.7
+++ ActionResources.properties 2001/03/13 22:31:49 1.8
@@ -11,7 +11,7 @@
destroyDataSource=Exception destroying application data source {0}
finalizing=Finalizing this controller servlet
initDataSource=Exception initializing application data source {0}
-mappingType=Must specify either "include" or "type" attribute for path {0}
+mappingType=Must specify one of "forward", "include" or "type" for path {0}
noInput=No input attribute for mapping path {0}
processInvalid=Invalid path {0} was requested
processPath=No process path included in this request
1.65 +51 -4
jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java
Index: ActionServlet.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- ActionServlet.java 2001/03/13 19:21:38 1.64
+++ ActionServlet.java 2001/03/13 22:31:50 1.65
@@ -1,7 +1,7 @@
/*
- * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.64
2001/03/13 19:21:38 craigmcc Exp $
- * $Revision: 1.64 $
- * $Date: 2001/03/13 19:21:38 $
+ * $Header:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionServlet.java,v 1.65
2001/03/13 22:31:50 craigmcc Exp $
+ * $Revision: 1.65 $
+ * $Date: 2001/03/13 22:31:50 $
*
* ====================================================================
*
@@ -230,7 +230,7 @@
* </ul>
*
* @author Craig R. McClanahan
- * @version $Revision: 1.64 $ $Date: 2001/03/13 19:21:38 $
+ * @version $Revision: 1.65 $ $Date: 2001/03/13 22:31:50 $
*/
public class ActionServlet
@@ -563,6 +563,8 @@
// Validate that exactly one of "include" or "type" is included
int n = 0;
+ if (mapping.getForward() != null)
+ n++;
if (mapping.getInclude() != null)
n++;
if (mapping.getType() != null)
@@ -1536,6 +1538,10 @@
if (!processValidate(mapping, formInstance, request, response))
return;
+ // Execute a forward if specified by this mapping
+ if (!processForward(mapping, request, response))
+ return;
+
// Execute an include if specified by this mapping
if (!processInclude(mapping, request, response))
return;
@@ -1764,6 +1770,47 @@
if (content != null)
response.setContentType(content);
+
+ }
+
+
+ /**
+ * Process a forward requested by this mapping, if any. Return
+ * <code>true</code> if processing of this request should continue (i.e.
+ * be processed by an Action class), or <code>false</code> if we have
+ * already handled this request.
+ *
+ * @param mapping The ActionMapping we are processing
+ * @param request The request we are processing
+ * @param response The response we are processing
+ *
+ * @exception IOException if the included resource throws an exception
+ * @exception ServletException if the included resource throws an
+ * exception
+ */
+ protected boolean processForward(ActionMapping mapping,
+ HttpServletRequest request,
+ HttpServletResponse response)
+ throws IOException, ServletException {
+
+ // Are we going to process this request?
+ String forward = mapping.getForward();
+ if (forward == null)
+ return (true);
+
+ // Construct a request dispatcher for the specified path
+ RequestDispatcher rd =
+ getServletContext().getRequestDispatcher(forward);
+ if (rd == null) {
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
+ internal.getMessage("requestDispatcher",
+ forward));
+ return (false);
+ }
+
+ // Delegate the processing of this request
+ rd.forward(request, response);
+ return (false);
}
1.8 +1 -1 jakarta-struts/web/example/WEB-INF/struts-config.xml
Index: struts-config.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/web/example/WEB-INF/struts-config.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- struts-config.xml 2001/03/11 02:50:12 1.7
+++ struts-config.xml 2001/03/13 22:31:54 1.8
@@ -115,7 +115,7 @@
<!-- Display the "walking tour" documentation -->
<action path="/tour"
- include="/tour.htm">
+ forward="/tour.htm">
</action>
<!-- The standard administrative actions available with Struts -->