类 ServletForwardingController
- java.lang.Object
- org.springframework.context.support.ApplicationObjectSupport
- org.springframework.web.context.support.WebApplicationObjectSupport
- org.springframework.web.servlet.support.WebContentGenerator
- org.springframework.web.servlet.mvc.AbstractController
- org.springframework.web.servlet.mvc.ServletForwardingController
public class ServletForwardingController extends AbstractController implements BeanNameAware
Spring Controller implementation that forwards to a named servlet, i.e. the "servlet-name" in web.xml rather than a URL path mapping. A target servlet doesn't even need a "servlet-mapping" in web.xml in the first place: A "servlet" declaration is sufficient.Useful to invoke an existing servlet via Spring's dispatching infrastructure, for example to apply Spring HandlerInterceptors to its requests. This will work even in a minimal Servlet container that does not support Servlet filters.
Example: web.xml, mapping all "/myservlet" requests to a Spring dispatcher. Also defines a custom "myServlet", but without servlet mapping.
<servlet> <servlet-name>myServlet</servlet-name> <servlet-class>mypackage.TestServlet</servlet-class> </servlet> <servlet> <servlet-name>myDispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>myDispatcher</servlet-name> <url-pattern>/myservlet</url-pattern> </servlet-mapping>
Example: myDispatcher-servlet.xml, in turn forwarding "/myservlet" to your servlet (identified by servlet name). All such requests will go through the configured HandlerInterceptor chain (e.g. an OpenSessionInViewInterceptor). From the servlet point of view, everything will work as usual.<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="interceptors"> <list> <ref bean="openSessionInViewInterceptor"/> </list> </property> <property name="mappings"> <props> <prop key="/myservlet">myServletForwardingController</prop> </props> </property> </bean> <bean id="myServletForwardingController" class="org.springframework.web.servlet.mvc.ServletForwardingController"> <property name="servletName"><value>myServlet</value></property> </bean>
- 从以下版本开始:
- 1.1.1
- 作者:
- Juergen Hoeller
- 另请参阅:
ServletWrappingController
,OpenEntityManagerInViewInterceptor
,OpenEntityManagerInViewFilter
字段概要
从类继承的字段 org.springframework.web.servlet.support.WebContentGenerator
HEADER_CACHE_CONTROL, METHOD_GET, METHOD_HEAD, METHOD_POST
从类继承的字段 org.springframework.context.support.ApplicationObjectSupport
logger
构造器概要
构造器 构造器 说明 ServletForwardingController()
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected ModelAndView
handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
Template method.void
setBeanName(String name)
Set the name of the bean in the bean factory that created this bean.void
setServletName(String servletName)
Set the name of the servlet to forward to, i.e. the "servlet-name" of the target servlet in web.xml.protected boolean
useInclude(HttpServletRequest request, HttpServletResponse response)
Determine whether to use RequestDispatcher'sinclude
orforward
method.从类继承的方法 org.springframework.web.servlet.mvc.AbstractController
handleRequest, isSynchronizeOnSession, setSynchronizeOnSession
从类继承的方法 org.springframework.web.servlet.support.WebContentGenerator
applyCacheControl, applyCacheSeconds, applyCacheSeconds, cacheForSeconds, cacheForSeconds, checkAndPrepare, checkAndPrepare, checkRequest, getAllowHeader, getCacheControl, getCacheSeconds, getSupportedMethods, getVaryByRequestHeaders, isAlwaysMustRevalidate, isRequireSession, isUseCacheControlHeader, isUseCacheControlNoStore, isUseExpiresHeader, prepareResponse, preventCaching, setAlwaysMustRevalidate, setCacheControl, setCacheSeconds, setRequireSession, setSupportedMethods, setUseCacheControlHeader, setUseCacheControlNoStore, setUseExpiresHeader, setVaryByRequestHeaders
从类继承的方法 org.springframework.web.context.support.WebApplicationObjectSupport
getServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContext
从类继承的方法 org.springframework.context.support.ApplicationObjectSupport
getApplicationContext, getMessageSourceAccessor, initApplicationContext, requiredContextClass, setApplicationContext
构造器详细资料
ServletForwardingController
public ServletForwardingController()
方法详细资料
setServletName
public void setServletName(String servletName)
Set the name of the servlet to forward to, i.e. the "servlet-name" of the target servlet in web.xml.Default is the bean name of this controller.
setBeanName
public void setBeanName(String name)
从接口复制的说明:BeanNameAware
Set the name of the bean in the bean factory that created this bean.Invoked after population of normal bean properties but before an init callback such as
InitializingBean.afterPropertiesSet()
or a custom init-method.- 指定者:
setBeanName
在接口中BeanNameAware
- 参数:
name
- the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use theBeanFactoryUtils.originalBeanName(String)
method to extract the original bean name (without suffix), if desired.
handleRequestInternal
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception
从类复制的说明:AbstractController
Template method. Subclasses must implement this. The contract is the same as forhandleRequest
.
useInclude
protected boolean useInclude(HttpServletRequest request, HttpServletResponse response)
Determine whether to use RequestDispatcher'sinclude
orforward
method.Performs a check whether an include URI attribute is found in the request, indicating an include request, and whether the response has already been committed. In both cases, an include will be performed, as a forward is not possible anymore.
- 参数:
request
- current HTTP requestresponse
- current HTTP response- 返回:
true
for include,false
for forward- 另请参阅:
RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
,RequestDispatcher.include(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
,ServletResponse.isCommitted()
,WebUtils.isIncludeRequest(javax.servlet.ServletRequest)