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 * <action path="/createSubscription" 50 * type="org.example.SubscriptionAction" 51 * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" 52 * parameter="create"> 53 * <forward path="/editSubscription.jsp"/> 54 * </action> 55 * 56 * <action path="/deleteSubscription" 57 * type="org.example.SubscriptionAction" 58 * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" 59 * parameter="delete" 60 * name="subscriptionForm" 61 * scope="request"> 62 * <forward path="/deletedSubscription.jsp"/> 63 * <forward name="input" path="/subscription.jsp" 64 * </action> 65 * 66 * <action path="/editSubscription" 67 * type="org.example.SubscriptionAction" 68 * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" 69 * parameter="edit"> 70 * <forward path="/editSubscription.jsp"/> 71 * </action> 72 * 73 * <action path="/listSubscriptions" 74 * type="org.example.SubscriptionAction" 75 * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" 76 * parameter="list"> 77 * <forward path="/subscriptionList.jsp"/> 78 * </action> 79 * 80 * <action path="/saveSubscription" 81 * type="org.example.SubscriptionAction" 82 * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" 83 * parameter="save" 84 * name="subscriptionForm" 85 * scope="request" 86 * validate="true"> 87 * <forward path="/savedSubscription.jsp"/> 88 * <forward name="input" path="/editSubscription.jsp" 89 * </action> 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 }