1 /* 2 * Copyright 2002-2005 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.web.servlet.mvc.throwaway; 18 19 import org.springframework.web.servlet.ModelAndView; 20 21 /** 22 * ThrowawayController is an alternative to Spring's default Controller interface, 23 * for executable per-request command instances that are not aware of the Servlet API. 24 * In contrast to Controller, implementing beans are not supposed to be defined as 25 * Servlet/Struts-style singletons that process a HttpServletRequest but rather as 26 * WebWork/Maverick-style prototypes that get populated with request parameters, 27 * executed to determine a view, and thrown away afterwards. 28 * 29 * <p>The main advantage of this controller programming model is that controllers 30 * are testable without HttpServletRequest/HttpServletResponse mocks, just like 31 * WebWork actions. They are still web UI workflow controllers: Spring does not 32 * aim for the arguably hard-to-achieve reusability of such controllers in non-web 33 * environments, as XWork (the generic command framework from WebWork2) does 34 * but just for ease of testing. 35 * 36 * <p>A ThrowawayController differs from the command notion of Base- or 37 * AbstractCommandController in that a ThrowawayController is an <i>executable</i> 38 * command that contains workflow logic to determine the next view to render, 39 * while BaseCommandController treats commands as plain parameter holders. 40 * 41 * <p>If binding request parameters to this controller fails, a fatal BindException 42 * will be thrown. 43 * 44 * <p>If you need access to the HttpServletRequest and/or HttpServletResponse, 45 * consider implementing Controller or deriving from AbstractCommandController. 46 * ThrowawayController is specifically intended for controllers that are not aware 47 * of the Servlet API at all. Accordingly, if you need to handle session form objects 48 * or even wizard forms, consider the corresponding Controller subclasses. 49 * 50 * @author Juergen Hoeller 51 * @since 08.12.2003 52 * @see org.springframework.web.servlet.mvc.Controller 53 * @see org.springframework.web.servlet.mvc.AbstractCommandController 54 */ 55 public interface ThrowawayController { 56 57 /** 58 * Execute this controller according to its bean properties. 59 * Gets invoked after a new instance of the controller has been populated with request 60 * parameters. Is supposed to return a ModelAndView in any case, as it is not able to 61 * generate a response itself. 62 * @return a ModelAndView to render 63 * @throws Exception in case of errors 64 */ 65 ModelAndView execute() throws Exception; 66 67 } 68