|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.servlet.GenericServlet javax.servlet.http.HttpServlet org.springframework.web.servlet.HttpServletBean org.springframework.web.servlet.FrameworkServlet
Base servlet for servlets within the web framework. Allows integration with an application context, in a JavaBean-based overall solution.
This class offers the following functionality:
Subclasses must implement doService() to handle requests. Because this extends HttpServletBean rather than HttpServlet directly, bean properties are mapped onto it. Subclasses can override initFrameworkServlet() for custom initialization.
Regards a "contextClass" parameter at the servlet init-param level, falling back to the default context class (XmlWebApplicationContext) if not found. With the default FrameworkServlet, a context class needs to implement ConfigurableWebApplicationContext.
Passes a "contextConfigLocation" servlet init-param to the context instance, parsing it into potentially multiple file paths which can be separated by any number of commas and spaces, like "test-servlet.xml, myServlet.xml". If not explicitly specified, the context implementation is supposed to build a default location from the namespace of the servlet.
Note: In case of multiple config locations, later bean definitions will override ones defined in earlier loaded files, at least when using one of Spring's default ApplicationContext implementations. This can be leveraged to deliberately override certain bean definitions via an extra XML file.
The default namespace is "'servlet-name'-servlet", e.g. "test-servlet" for a servlet-name "test" (leading to a "/WEB-INF/test-servlet.xml" default location with XmlWebApplicationContext). The namespace can also be set explicitly via the "namespace" servlet init-param.
doService(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
,
initFrameworkServlet()
,
setContextClass(java.lang.Class)
,
setContextConfigLocation(java.lang.String)
,
setNamespace(java.lang.String)
,
Serialized FormField Summary | |
static java.lang.Class |
DEFAULT_CONTEXT_CLASS
Default context class for FrameworkServlet. |
static java.lang.String |
DEFAULT_NAMESPACE_SUFFIX
Suffix for WebApplicationContext namespaces. |
static java.lang.String |
SERVLET_CONTEXT_PREFIX
Prefix for the ServletContext attribute for the WebApplicationContext. |
Fields inherited from class org.springframework.web.servlet.HttpServletBean |
logger |
Constructor Summary | |
FrameworkServlet()
|
Method Summary | |
protected WebApplicationContext |
createWebApplicationContext(WebApplicationContext parent)
Instantiate the WebApplicationContext for this servlet, either a default XmlWebApplicationContext or a custom context class if set. |
void |
destroy()
Close the WebApplicationContext of this servlet. |
protected void |
doGet(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
It's up to each subclass to decide whether or not it supports a request method. |
protected void |
doPost(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
It's up to each subclass to decide whether or not it supports a request method. |
protected abstract void |
doService(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Subclasses must implement this method to do the work of request handling. |
java.lang.Class |
getContextClass()
Return the custom context class. |
java.lang.String |
getContextConfigLocation()
Return the explicit context config location, if any. |
java.lang.String |
getNamespace()
Return the namespace for this servlet, falling back to default scheme if no custom namespace was set: e.g. |
java.lang.String |
getServletContextAttributeName()
Return the ServletContext attribute name for this servlet's WebApplicationContext. |
WebApplicationContext |
getWebApplicationContext()
Return this servlet's WebApplicationContext. |
protected void |
initFrameworkServlet()
This method will be invoked after any bean properties have been set and the WebApplicationContext has been loaded. |
protected void |
initServletBean()
Overridden method of HttpServletBean, invoked after any bean properties have been set. |
protected WebApplicationContext |
initWebApplicationContext()
Initialize and publish the WebApplicationContext for this servlet. |
boolean |
isPublishContext()
Return whether to publish this servlet's context as a ServletContext attribute. |
void |
setContextClass(java.lang.Class contextClass)
Set a custom context class. |
void |
setContextConfigLocation(java.lang.String contextConfigLocation)
Set the context config location explicitly, instead of relying on the default location built from the namespace. |
void |
setNamespace(java.lang.String namespace)
Set a custom namespace for this servlet, to be used for building a default context config location. |
void |
setPublishContext(boolean publishContext)
Set whether to publish this servlet's context as a ServletContext attribute, available to all objects in the web container. |
Methods inherited from class org.springframework.web.servlet.HttpServletBean |
addRequiredProperty, init |
Methods inherited from class javax.servlet.http.HttpServlet |
doDelete, doHead, doOptions, doPut, doTrace, getLastModified, service, service |
Methods inherited from class javax.servlet.GenericServlet |
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String DEFAULT_NAMESPACE_SUFFIX
public static final java.lang.Class DEFAULT_CONTEXT_CLASS
XmlWebApplicationContext
public static final java.lang.String SERVLET_CONTEXT_PREFIX
Constructor Detail |
public FrameworkServlet()
Method Detail |
public void setContextClass(java.lang.Class contextClass)
createWebApplicationContext(org.springframework.web.context.WebApplicationContext)
public java.lang.Class getContextClass()
public void setNamespace(java.lang.String namespace)
public java.lang.String getNamespace()
public void setContextConfigLocation(java.lang.String contextConfigLocation)
public java.lang.String getContextConfigLocation()
public void setPublishContext(boolean publishContext)
This is especially handy during testing, although it is debatable whether it's good practice to let other application objects access the context this way.
public boolean isPublishContext()
protected final void initServletBean() throws javax.servlet.ServletException, BeansException
initServletBean
in class HttpServletBean
javax.servlet.ServletException
- if subclass initialization fails
BeansException
protected WebApplicationContext initWebApplicationContext() throws BeansException
BeansException
- if the context couldn't be initializedcreateWebApplicationContext(org.springframework.web.context.WebApplicationContext)
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) throws BeansException
BeansException
- if the context couldn't be initializedsetContextClass(java.lang.Class)
,
XmlWebApplicationContext
public java.lang.String getServletContextAttributeName()
public final WebApplicationContext getWebApplicationContext()
protected void initFrameworkServlet() throws javax.servlet.ServletException, BeansException
javax.servlet.ServletException
- in case of an initialization exception
BeansException
- if thrown by ApplicationContext methodsprotected final void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
javax.servlet.ServletException
java.io.IOException
protected final void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
javax.servlet.ServletException
java.io.IOException
protected abstract void doService(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.lang.Exception
java.lang.Exception
- in case of any kind of processing failureHttpServlet.doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
,
HttpServlet.doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
public void destroy()
ConfigurableApplicationContext.close()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |