/* * $Id: ServletMappingDispatcher.java 729832 2008-12-29 05:12:58Z pbenedict $ * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.struts.dispatcher.servlet; import org.apache.struts.chain.contexts.ActionContext; import org.apache.struts.chain.contexts.ServletActionContext; import org.apache.struts.dispatcher.AbstractMappingDispatcher; import javax.servlet.http.HttpServletResponse; /** * This servlet-based dispatcher uses the configuration value of the * <code>parameter</code> attribute from the corresponding * {@link org.apache.struts.action.ActionMapping} to pick the appropriate method * on the action. Because mapping characteristics may differ between the various * handlers, actions can be combined in the same class that, differ in their use * of method signatures, forms, and/or validation. * <p> * For example, a single action may manage a subscription process by defining * the following methods: * <ul> * <li><code>public void create(ActionContext context)</code></li> * <li><code>public void delete(ActionContext context)</code></li> * <li><code>public String edit(ActionContext context)</code></li> * <li><code>public ActionForward list(ActionContext context)</code></li> * <li><code>public String save(ActionContext context)</code></li> * </ul> * for which a corresponding configuration would exist: * * <pre><code> * <action path="/createSubscription" * type="org.example.SubscriptionAction" * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" * parameter="create"> * <forward path="/editSubscription.jsp"/> * </action> * * <action path="/deleteSubscription" * type="org.example.SubscriptionAction" * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" * parameter="delete" * name="subscriptionForm" * scope="request"> * <forward path="/deletedSubscription.jsp"/> * <forward name="input" path="/subscription.jsp" * </action> * * <action path="/editSubscription" * type="org.example.SubscriptionAction" * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" * parameter="edit"> * <forward path="/editSubscription.jsp"/> * </action> * * <action path="/listSubscriptions" * type="org.example.SubscriptionAction" * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" * parameter="list"> * <forward path="/subscriptionList.jsp"/> * </action> * * <action path="/saveSubscription" * type="org.example.SubscriptionAction" * dispatcher="org.apache.struts.dispatcher.servlet.ServletMappingDispatcher" * parameter="save" * name="subscriptionForm" * scope="request" * validate="true"> * <forward path="/savedSubscription.jsp"/> * <forward name="input" path="/editSubscription.jsp" * </action> * </code></pre> * * @version $Rev: 729832 $ * @since Struts 1.4 */ public class ServletMappingDispatcher extends AbstractMappingDispatcher { private static final long serialVersionUID = 1L; /** * Constructs a new servlet mapping dispatcher. */ public ServletMappingDispatcher() { super(new ServletMethodResolver()); } /** * Sends the 404 HTTP error response. * * @return always <code>null</code> since the response is handled directly */ protected Object unspecified(ActionContext context) throws Exception { HttpServletResponse response = ((ServletActionContext) context).getResponse(); response.sendError(HttpServletResponse.SC_NOT_FOUND); return null; } }