View Javadoc
1   /*
2    * $Id$
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  package org.apache.struts.dispatcher.servlet;
22  
23  import org.apache.struts.chain.contexts.ActionContext;
24  import org.apache.struts.chain.contexts.ServletActionContext;
25  import org.apache.struts.dispatcher.AbstractMappingDispatcher;
26  
27  import jakarta.servlet.http.HttpServletResponse;
28  
29  /**
30   * This servlet-based dispatcher uses the configuration value of the
31   * <code>parameter</code> attribute from the corresponding
32   * {@link org.apache.struts.action.ActionMapping} to pick the appropriate method
33   * on the action. Because mapping characteristics may differ between the various
34   * handlers, actions can be combined in the same class that, differ in their use
35   * of method signatures, forms, and/or validation.
36   * <p>
37   * For example, a single action may manage a subscription process by defining
38   * the following methods:
39   * <ul>
40   * <li><code>public void create(ActionContext context)</code></li>
41   * <li><code>public void delete(ActionContext context)</code></li>
42   * <li><code>public String edit(ActionContext context)</code></li>
43   * <li><code>public ActionForward list(ActionContext context)</code></li>
44   * <li><code>public String save(ActionContext context)</code></li>
45   * </ul>
46   * for which a corresponding configuration would exist:
47   *
48   * <pre><code>
49   *  &lt;action path=&quot;/createSubscription&quot;
50   *          type=&quot;org.example.SubscriptionAction&quot;
51   *          dispatcher=&quot;org.apache.struts.dispatcher.servlet.ServletMappingDispatcher&quot;
52   *          parameter=&quot;create&quot;&gt;
53   *      &lt;forward path=&quot;/editSubscription.jsp&quot;/&gt;
54   *  &lt;/action&gt;
55   *
56   *  &lt;action path=&quot;/deleteSubscription&quot;
57   *          type=&quot;org.example.SubscriptionAction&quot;
58   *          dispatcher=&quot;org.apache.struts.dispatcher.servlet.ServletMappingDispatcher&quot;
59   *          parameter=&quot;delete&quot;
60   *          name=&quot;subscriptionForm&quot;
61   *          scope=&quot;request&quot;&gt;
62   *      &lt;forward path=&quot;/deletedSubscription.jsp&quot;/&gt;
63   *      &lt;forward name=&quot;input&quot; path=&quot;/subscription.jsp&quot;
64   *  &lt;/action&gt;
65   *
66   *  &lt;action path=&quot;/editSubscription&quot;
67   *          type=&quot;org.example.SubscriptionAction&quot;
68   *          dispatcher=&quot;org.apache.struts.dispatcher.servlet.ServletMappingDispatcher&quot;
69   *          parameter=&quot;edit&quot;&gt;
70   *      &lt;forward path=&quot;/editSubscription.jsp&quot;/&gt;
71   *  &lt;/action&gt;
72   *
73   *  &lt;action path=&quot;/listSubscriptions&quot;
74   *          type=&quot;org.example.SubscriptionAction&quot;
75   *          dispatcher=&quot;org.apache.struts.dispatcher.servlet.ServletMappingDispatcher&quot;
76   *          parameter=&quot;list&quot;&gt;
77   *      &lt;forward path=&quot;/subscriptionList.jsp&quot;/&gt;
78   *  &lt;/action&gt;
79   *
80   *  &lt;action path=&quot;/saveSubscription&quot;
81   *          type=&quot;org.example.SubscriptionAction&quot;
82   *          dispatcher=&quot;org.apache.struts.dispatcher.servlet.ServletMappingDispatcher&quot;
83   *          parameter=&quot;save&quot;
84   *          name=&quot;subscriptionForm&quot;
85   *          scope=&quot;request&quot;
86   *          validate=&quot;true&quot;&gt;
87   *      &lt;forward path=&quot;/savedSubscription.jsp&quot;/&gt;
88   *      &lt;forward name=&quot;input&quot; path=&quot;/editSubscription.jsp&quot;
89   *  &lt;/action&gt;
90   * </code></pre>
91   *
92   * @version $Rev$
93   * @since Struts 1.4
94   */
95  public class ServletMappingDispatcher extends AbstractMappingDispatcher {
96  
97      private static final long serialVersionUID = 1L;
98  
99      /**
100      * Constructs a new servlet mapping dispatcher.
101      */
102     public ServletMappingDispatcher() {
103         super(new ServletMethodResolver());
104     }
105 
106     /**
107      * Sends the 404 HTTP error response.
108      *
109      * @return always <code>null</code> since the response is handled directly
110      */
111     protected Object unspecified(ActionContext context) throws Exception {
112         HttpServletResponse response = ((ServletActionContext) context).getResponse();
113         response.sendError(HttpServletResponse.SC_NOT_FOUND);
114         return null;
115     }
116 
117 }